From a48dd1659b55ab88f5db841579f7d0a36ac537b5 Mon Sep 17 00:00:00 2001 From: nsne <15527632169@163.com> Date: Tue, 1 Jun 2021 11:19:52 +0800 Subject: [PATCH] feat: add custom handleUnexpectedError for network error --- packages/plugin-request/src/request.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/plugin-request/src/request.ts b/packages/plugin-request/src/request.ts index 0d8d807ee..87e633c65 100644 --- a/packages/plugin-request/src/request.ts +++ b/packages/plugin-request/src/request.ts @@ -95,6 +95,7 @@ export interface RequestConfig extends RequestOptionsInit { errorConfig?: { errorPage?: string; adaptor?: (resData: any, ctx: Context) => ErrorInfoStructure; + handleUnexpectedError?: (error: RequestError) => void; }; middlewares?: OnionMiddleware[]; requestInterceptors?: RequestInterceptor[]; @@ -147,6 +148,10 @@ const getRequestMethod = () => { const errorAdaptor = requestConfig.errorConfig?.adaptor || (resData => resData); + const handleUnexpectedError = + requestConfig.errorConfig?.handleUnexpectedError || + (error => message.error(error.message || 'Request error, please retry.')); + requestMethodInstance = extend({ errorHandler: (error: RequestError) => { // @ts-ignore @@ -200,7 +205,7 @@ const getRequestMethod = () => { break; } } else { - message.error(error.message || 'Request error, please retry.'); + handleUnexpectedError(error); } throw error; },