mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-18 01:36:37 +08:00
refactor(projects): axios处理的请求结果去除网路状态
This commit is contained in:
parent
e1dacdbc39
commit
0569666a8f
@ -32,8 +32,6 @@ export interface CustomSuccessRequestResult<ResponseData> {
|
|||||||
error: null;
|
error: null;
|
||||||
/** 请求数据 */
|
/** 请求数据 */
|
||||||
data: ResponseData;
|
data: ResponseData;
|
||||||
/** 网络状态 */
|
|
||||||
networkStatus: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 自定义的请求失败结果 */
|
/** 自定义的请求失败结果 */
|
||||||
@ -42,8 +40,6 @@ export interface CustomFailRequestResult {
|
|||||||
error: RequestServiceError;
|
error: RequestServiceError;
|
||||||
/** 请求数据 */
|
/** 请求数据 */
|
||||||
data: null;
|
data: null;
|
||||||
/** 网络状态 */
|
|
||||||
networkStatus: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 自定义的请求结果 */
|
/** 自定义的请求结果 */
|
||||||
|
@ -15,8 +15,7 @@ export default class Request {
|
|||||||
static successHandler<ResponseData>(response: AxiosResponse) {
|
static successHandler<ResponseData>(response: AxiosResponse) {
|
||||||
const successResult: CustomSuccessRequestResult<ResponseData> = {
|
const successResult: CustomSuccessRequestResult<ResponseData> = {
|
||||||
data: response as unknown as ResponseData,
|
data: response as unknown as ResponseData,
|
||||||
error: null,
|
error: null
|
||||||
networkStatus: window.navigator.onLine
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return successResult;
|
return successResult;
|
||||||
@ -25,8 +24,7 @@ export default class Request {
|
|||||||
static failHandler(error: RequestServiceError) {
|
static failHandler(error: RequestServiceError) {
|
||||||
const failResult: CustomFailRequestResult = {
|
const failResult: CustomFailRequestResult = {
|
||||||
data: null,
|
data: null,
|
||||||
error,
|
error
|
||||||
networkStatus: window.navigator.onLine
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return failResult;
|
return failResult;
|
||||||
|
@ -34,7 +34,7 @@ export function handleAxiosError(axiosError: AxiosError) {
|
|||||||
// 请求不成功的错误
|
// 请求不成功的错误
|
||||||
const errorCode: ErrorStatus = axiosError.response.status as ErrorStatus;
|
const errorCode: ErrorStatus = axiosError.response.status as ErrorStatus;
|
||||||
const msg = ERROR_STATUS[errorCode] || DEFAULT_REQUEST_ERROR_MSG;
|
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);
|
showErrorMsg(error);
|
||||||
|
@ -14,13 +14,11 @@ export function resultMiddleware<MiddlewareData>(
|
|||||||
const hasError = errorIndex > -1;
|
const hasError = errorIndex > -1;
|
||||||
const successResult: CustomSuccessRequestResult<MiddlewareData> = {
|
const successResult: CustomSuccessRequestResult<MiddlewareData> = {
|
||||||
data: resultHandler(...requests.map(item => item.data)),
|
data: resultHandler(...requests.map(item => item.data)),
|
||||||
error: null,
|
error: null
|
||||||
networkStatus: window.navigator.onLine
|
|
||||||
};
|
};
|
||||||
const failResult: CustomFailRequestResult = {
|
const failResult: CustomFailRequestResult = {
|
||||||
data: null,
|
data: null,
|
||||||
error: requests[errorIndex].error!,
|
error: requests[errorIndex].error!
|
||||||
networkStatus: window.navigator.onLine
|
|
||||||
};
|
};
|
||||||
return hasError ? failResult : successResult;
|
return hasError ? failResult : successResult;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user