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 | 18 | import { joinTimestamp, formatRequestDate } from './helper'; |
19 | 19 | import { useUserStoreWithOut } from '/@/store/modules/user'; |
20 | 20 | import { AxiosRetry } from '/@/utils/http/axios/axiosRetry'; |
21 | +import axios from 'axios'; | |
21 | 22 | |
22 | 23 | const globSetting = useGlobSetting(); |
23 | 24 | const urlPrefix = globSetting.urlPrefix; |
... | ... | @@ -111,7 +112,11 @@ const transform: AxiosTransform = { |
111 | 112 | } else { |
112 | 113 | if (!isString(params)) { |
113 | 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 | 120 | config.data = data; |
116 | 121 | config.params = params; |
117 | 122 | } else { |
... | ... | @@ -169,6 +174,10 @@ const transform: AxiosTransform = { |
169 | 174 | const err: string = error?.toString?.() ?? ''; |
170 | 175 | let errMessage = ''; |
171 | 176 | |
177 | + if (axios.isCancel(error)) { | |
178 | + return Promise.reject(error); | |
179 | + } | |
180 | + | |
172 | 181 | try { |
173 | 182 | if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) { |
174 | 183 | errMessage = t('sys.api.apiTimeoutMessage'); | ... | ... |