Skip to content

Commit

Permalink
fix(projects): fix request msg
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 11, 2024
1 parent 88f2641 commit 47b54b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function createCommonRequest<ResponseData = any>(
'the backend request error',
BACKEND_ERROR_CODE,
response.config,
response,
response.request
response.request,
response
);

await opts.onError(backendError);
Expand Down
10 changes: 5 additions & 5 deletions src/service/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const request = createFlatRequest<App.Service.Response>(
return response.data.code === '0000';
},
async onBackendFail(_response) {
// when the backend response code is not 200, it means the request is fail
// when the backend response code is not "0000", it means the request is fail
// for example: the token is expired, refetch token and retry request
},
transformBackendResponse(response) {
Expand All @@ -43,7 +43,7 @@ export const request = createFlatRequest<App.Service.Response>(

// show backend error message
if (error.code === BACKEND_ERROR_CODE) {
message = error.request?.data.msg || message;
message = error.response?.data?.msg || message;
}

window.$message?.error(message);
Expand All @@ -67,12 +67,12 @@ export const demoRequest = createRequest<App.Service.DemoResponse>(
return config;
},
isBackendSuccess(response) {
// when the backend response code is 200, it means the request is success
// when the backend response code is "200", it means the request is success
// you can change this logic by yourself
return response.data.status === '200';
},
async onBackendFail(_response) {
// when the backend response code is not 200, it means the request is fail
// when the backend response code is not "200", it means the request is fail
// for example: the token is expired, refetch token and retry request
},
transformBackendResponse(response) {
Expand All @@ -85,7 +85,7 @@ export const demoRequest = createRequest<App.Service.DemoResponse>(

// show backend error message
if (error.code === BACKEND_ERROR_CODE) {
message = error.request?.data.message || message;
message = error.response?.data?.message || message;
}

window.$message?.error(message);
Expand Down

0 comments on commit 47b54b0

Please sign in to comment.