fix(projects): fix request msg

This commit is contained in:
Soybean 2024-02-04 00:14:17 +08:00
parent 6ea9b85ff1
commit ae6b6134f3
2 changed files with 7 additions and 7 deletions

View File

@ -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);

View File

@ -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) {
@ -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);
@ -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) {
@ -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);