Commit b1f78c6696f5dbb387361307cdec1ef1d37e610b
Committed by
GitHub
1 parent
dda27477
fix: 取消重复请求,错误处理 (#2184)
Showing
1 changed file
with
10 additions
and
1 deletions
src/utils/http/axios/index.ts
@@ -18,6 +18,7 @@ import { useI18n } from '/@/hooks/web/useI18n'; | @@ -18,6 +18,7 @@ import { useI18n } from '/@/hooks/web/useI18n'; | ||
18 | import { joinTimestamp, formatRequestDate } from './helper'; | 18 | import { joinTimestamp, formatRequestDate } from './helper'; |
19 | import { useUserStoreWithOut } from '/@/store/modules/user'; | 19 | import { useUserStoreWithOut } from '/@/store/modules/user'; |
20 | import { AxiosRetry } from '/@/utils/http/axios/axiosRetry'; | 20 | import { AxiosRetry } from '/@/utils/http/axios/axiosRetry'; |
21 | +import axios from 'axios'; | ||
21 | 22 | ||
22 | const globSetting = useGlobSetting(); | 23 | const globSetting = useGlobSetting(); |
23 | const urlPrefix = globSetting.urlPrefix; | 24 | const urlPrefix = globSetting.urlPrefix; |
@@ -111,7 +112,11 @@ const transform: AxiosTransform = { | @@ -111,7 +112,11 @@ const transform: AxiosTransform = { | ||
111 | } else { | 112 | } else { |
112 | if (!isString(params)) { | 113 | if (!isString(params)) { |
113 | formatDate && formatRequestDate(params); | 114 | formatDate && formatRequestDate(params); |
114 | - if (Reflect.has(config, 'data') && config.data && (Object.keys(config.data).length > 0 || config.data instanceof FormData)) { | 115 | + if ( |
116 | + Reflect.has(config, 'data') && | ||
117 | + config.data && | ||
118 | + (Object.keys(config.data).length > 0 || config.data instanceof FormData) | ||
119 | + ) { | ||
115 | config.data = data; | 120 | config.data = data; |
116 | config.params = params; | 121 | config.params = params; |
117 | } else { | 122 | } else { |
@@ -169,6 +174,10 @@ const transform: AxiosTransform = { | @@ -169,6 +174,10 @@ const transform: AxiosTransform = { | ||
169 | const err: string = error?.toString?.() ?? ''; | 174 | const err: string = error?.toString?.() ?? ''; |
170 | let errMessage = ''; | 175 | let errMessage = ''; |
171 | 176 | ||
177 | + if (axios.isCancel(error)) { | ||
178 | + return Promise.reject(error); | ||
179 | + } | ||
180 | + | ||
172 | try { | 181 | try { |
173 | if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) { | 182 | if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) { |
174 | errMessage = t('sys.api.apiTimeoutMessage'); | 183 | errMessage = t('sys.api.apiTimeoutMessage'); |