Skip to content

Commit

Permalink
fixbug: 请求拦截问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jun 14, 2022
1 parent 1070948 commit 70c7bc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/utils/axios/errorConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { AxiosError } from 'axios';
import { Result } from '#/axios';
import type { AxiosResponse } from 'axios';

export const errorData = (res: AxiosError) => {
export const errorData = (res: AxiosResponse<Result<any>>) => {
return {
data: null,
message: res.message,
code: res.code,
message: res.data.message,
code: res.data.code,
};
};
3 changes: 1 addition & 2 deletions src/utils/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { iAxios } from './iAxios';
import { checkStatus } from './axiosStatus';
import { isString } from 'lodash';
import { useMessage } from '@/hooks/web/useMessage';
import { AxiosError } from 'axios';
import { errorData } from './errorConfig';

const { createErrorModal, createErrorMsg } = useMessage();
Expand All @@ -22,14 +21,14 @@ const interceptor: AxiosInterceptor = {
*/
const { data } = res;
const { errorMessageMode } = options;
if (!data || !data.data) return errorData(res as unknown as AxiosError);

if (data.code === -1) {
if (errorMessageMode === 'modal') {
createErrorModal(data.message);
} else if (errorMessageMode === 'message') {
createErrorMsg(data.message);
}
return errorData(res);
}

return data;
Expand Down

0 comments on commit 70c7bc4

Please sign in to comment.