chore deps: upgrade axios to 1.x

This commit is contained in:
baorong
2026-02-19 21:30:25 +08:00
parent 0d82eca735
commit 4d1851ddd2
2 changed files with 10 additions and 9 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
"@lingui/react": "^5.0.0",
"@rc-component/picker": "^1.9.0",
"antd": "^6.0.0",
"axios": "^0.21.4",
"axios": "^2.1.0",
"classnames": "^2.5.1",
"d3-shape": "^2.1.0",
"dayjs": "^1.11.10",
+9 -8
View File
@@ -4,7 +4,6 @@ import { parse, compile } from 'path-to-regexp'
import { message } from 'antd'
import { CANCEL_REQUEST_MESSAGE } from 'utils/constant'
const { CancelToken } = axios
window.cancelRequest = new Map()
export default function request(options) {
@@ -33,11 +32,12 @@ export default function request(options) {
}
options.url = url
options.cancelToken = new CancelToken(cancel => {
window.cancelRequest.set(Symbol(Date.now()), {
pathname: window.location.pathname,
cancel,
})
// Use AbortController signal for request cancellation (compatible with axios v2)
const controller = new AbortController()
options.signal = controller.signal
window.cancelRequest.set(Symbol(Date.now()), {
pathname: window.location.pathname,
abort: reason => controller.abort(reason || CANCEL_REQUEST_MESSAGE),
})
return axios(options)
@@ -62,9 +62,10 @@ export default function request(options) {
})
})
.catch(error => {
const { response, message: errMsg } = error
const { response, message: errMsg, code, name } = error
if (String(errMsg) === CANCEL_REQUEST_MESSAGE) {
// axios v2 cancellation can surface as ERR_CANCELED / CanceledError or message matching our sentinel
if (String(errMsg) === CANCEL_REQUEST_MESSAGE || code === 'ERR_CANCELED' || name === 'CanceledError') {
return {
success: false,
}