From 136cbb1e3bc056c88cfa21fca612d3ab72b4d119 Mon Sep 17 00:00:00 2001 From: Captain <49203535+MssText@users.noreply.github.com> Date: 星期六, 19 三月 2022 00:07:34 +0800 Subject: [PATCH] feat: add request retry (#1553) --- src/utils/http/axios/index.ts | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index 97dee45..8c5c00e 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -17,6 +17,7 @@ import { useI18n } from '/@/hooks/web/useI18n'; import { joinTimestamp, formatRequestDate } from './helper'; import { useUserStoreWithOut } from '/@/store/modules/user'; +import { AxiosRetry } from '/@/utils/http/axios/axiosRetry'; const globSetting = useGlobSetting(); const urlPrefix = globSetting.urlPrefix; @@ -158,7 +159,7 @@ /** * @description: 鍝嶅簲閿欒澶勭悊 */ - responseInterceptorsCatch: (error: any) => { + responseInterceptorsCatch: (axiosInstance: AxiosResponse, error: any) => { const { t } = useI18n(); const errorLogStore = useErrorLogStoreWithOut(); errorLogStore.addAjaxErrorInfo(error); @@ -189,6 +190,14 @@ } checkStatus(error?.response?.status, msg, errorMessageMode); + + // 娣诲姞鑷姩閲嶈瘯鏈哄埗 淇濋櫓璧疯 鍙拡瀵笹ET璇锋眰 + const retryRequest = new AxiosRetry(); + const { isOpenRetry } = config.requestOptions.retryRequest; + config.method?.toUpperCase() === RequestEnum.GET && + isOpenRetry && + // @ts-ignore + retryRequest.retry(axiosInstance, error); return Promise.reject(error); }, }; @@ -234,6 +243,11 @@ ignoreCancelToken: true, // 鏄惁鎼哄甫token withToken: true, + retryRequest: { + isOpenRetry: true, + count: 5, + waitTime: 100, + }, }, }, opt || {}, -- Gitblit v1.8.0