refactor(projects): axios处理的请求结果去除网路状态
This commit is contained in:
parent
e1dacdbc39
commit
0569666a8f
@ -32,8 +32,6 @@ export interface CustomSuccessRequestResult<ResponseData> {
|
||||
error: null;
|
||||
/** 请求数据 */
|
||||
data: ResponseData;
|
||||
/** 网络状态 */
|
||||
networkStatus: boolean;
|
||||
}
|
||||
|
||||
/** 自定义的请求失败结果 */
|
||||
@ -42,8 +40,6 @@ export interface CustomFailRequestResult {
|
||||
error: RequestServiceError;
|
||||
/** 请求数据 */
|
||||
data: null;
|
||||
/** 网络状态 */
|
||||
networkStatus: boolean;
|
||||
}
|
||||
|
||||
/** 自定义的请求结果 */
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user