From 0569666a8f015f26ece240a93133095f698568a1 Mon Sep 17 00:00:00 2001 From: Soybean <2570172956@qq.com> Date: Tue, 23 Nov 2021 09:52:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(projects):=20axios=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9A=84=E8=AF=B7=E6=B1=82=E7=BB=93=E6=9E=9C=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E7=BD=91=E8=B7=AF=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interface/common/service.ts | 4 ---- src/service/request/axios/request.ts | 6 ++---- src/service/request/helpers/error.ts | 2 +- src/service/request/helpers/handler.ts | 6 ++---- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/interface/common/service.ts b/src/interface/common/service.ts index 85b06335..f86df036 100644 --- a/src/interface/common/service.ts +++ b/src/interface/common/service.ts @@ -32,8 +32,6 @@ export interface CustomSuccessRequestResult { error: null; /** 请求数据 */ data: ResponseData; - /** 网络状态 */ - networkStatus: boolean; } /** 自定义的请求失败结果 */ @@ -42,8 +40,6 @@ export interface CustomFailRequestResult { error: RequestServiceError; /** 请求数据 */ data: null; - /** 网络状态 */ - networkStatus: boolean; } /** 自定义的请求结果 */ diff --git a/src/service/request/axios/request.ts b/src/service/request/axios/request.ts index c0df655c..17191510 100644 --- a/src/service/request/axios/request.ts +++ b/src/service/request/axios/request.ts @@ -15,8 +15,7 @@ export default class Request { static successHandler(response: AxiosResponse) { const successResult: CustomSuccessRequestResult = { data: response as unknown as ResponseData, - error: null, - networkStatus: window.navigator.onLine + error: null }; return successResult; @@ -25,8 +24,7 @@ export default class Request { static failHandler(error: RequestServiceError) { const failResult: CustomFailRequestResult = { data: null, - error, - networkStatus: window.navigator.onLine + error }; return failResult; diff --git a/src/service/request/helpers/error.ts b/src/service/request/helpers/error.ts index db4d8138..3e5a62ba 100644 --- a/src/service/request/helpers/error.ts +++ b/src/service/request/helpers/error.ts @@ -34,7 +34,7 @@ export function handleAxiosError(axiosError: AxiosError) { // 请求不成功的错误 const errorCode: ErrorStatus = axiosError.response.status as ErrorStatus; const msg = ERROR_STATUS[errorCode] || DEFAULT_REQUEST_ERROR_MSG; - Object.assign(error, { code: errorCode, msg }); + Object.assign(error, { code: errorCode || DEFAULT_REQUEST_ERROR_CODE, msg }); } showErrorMsg(error); diff --git a/src/service/request/helpers/handler.ts b/src/service/request/helpers/handler.ts index 5bae2e63..768a0232 100644 --- a/src/service/request/helpers/handler.ts +++ b/src/service/request/helpers/handler.ts @@ -14,13 +14,11 @@ export function resultMiddleware( const hasError = errorIndex > -1; const successResult: CustomSuccessRequestResult = { data: resultHandler(...requests.map(item => item.data)), - error: null, - networkStatus: window.navigator.onLine + error: null }; const failResult: CustomFailRequestResult = { data: null, - error: requests[errorIndex].error!, - networkStatus: window.navigator.onLine + error: requests[errorIndex].error! }; return hasError ? failResult : successResult; }