From ae6b6134f3cc181494ab98c3d82a9b2f686ce216 Mon Sep 17 00:00:00 2001 From: Soybean Date: Sun, 4 Feb 2024 00:14:17 +0800 Subject: [PATCH] fix(projects): fix request msg --- packages/axios/src/index.ts | 4 ++-- src/service/request/index.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/axios/src/index.ts b/packages/axios/src/index.ts index bda1d8ab..4d52024c 100644 --- a/packages/axios/src/index.ts +++ b/packages/axios/src/index.ts @@ -61,8 +61,8 @@ function createCommonRequest( 'the backend request error', BACKEND_ERROR_CODE, response.config, - response, - response.request + response.request, + response ); await opts.onError(backendError); diff --git a/src/service/request/index.ts b/src/service/request/index.ts index 7f9552c0..fb2a40f3 100644 --- a/src/service/request/index.ts +++ b/src/service/request/index.ts @@ -30,7 +30,7 @@ export const request = createFlatRequest( 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( // 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( 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( // 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);