Skip to content

Commit

Permalink
refactor(projects): axios处理的请求结果去除网路状态
Browse files Browse the repository at this point in the history
  • Loading branch information
Soybean committed Nov 23, 2021
1 parent e1dacdb commit 0569666
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/interface/common/service.ts
Expand Up @@ -32,8 +32,6 @@ export interface CustomSuccessRequestResult<ResponseData> {
error: null;
/** 请求数据 */
data: ResponseData;
/** 网络状态 */
networkStatus: boolean;
}

/** 自定义的请求失败结果 */
Expand All @@ -42,8 +40,6 @@ export interface CustomFailRequestResult {
error: RequestServiceError;
/** 请求数据 */
data: null;
/** 网络状态 */
networkStatus: boolean;
}

/** 自定义的请求结果 */
Expand Down
6 changes: 2 additions & 4 deletions src/service/request/axios/request.ts
Expand Up @@ -15,8 +15,7 @@ export default class Request {
static successHandler<ResponseData>(response: AxiosResponse) {
const successResult: CustomSuccessRequestResult<ResponseData> = {
data: response as unknown as ResponseData,
error: null,
networkStatus: window.navigator.onLine
error: null
};

return successResult;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/service/request/helpers/error.ts
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/service/request/helpers/handler.ts
Expand Up @@ -14,13 +14,11 @@ export function resultMiddleware<MiddlewareData>(
const hasError = errorIndex > -1;
const successResult: CustomSuccessRequestResult<MiddlewareData> = {
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;
}

1 comment on commit 0569666

@vercel
Copy link

@vercel vercel bot commented on 0569666 Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.