admin管理员组文章数量:1406436
After upgrading from Axios v0.27.2 to v1.1.2, I get an error in the following because response.error
now returns undefined
import axios from 'axios'
const axiosInstance = axios.create({ baseURL: 'http://localhost:8080' })
export default axiosInstance
// the definition of the functions saveNewToken, showError have been
// omitted in the interest of brevity
axiosInstance.interceptors.response.use(saveNewToken, error => {
// The error occurs here because error.response is undefined
switch (error.response.status) {
case 400:
showError(error.response.data, 'Validation error: please correct any errors before re-submitting')
break
}
return Promise.reject(error)
})
So I guess the response interceptors API changed such that error.response
is not a valid property of the argument passed to the onRejected
handler.
I've read through the Axios release notes and looked for a v1 migration guide for a list of required changes, but I can't find anything specific about API changes in v1.
After upgrading from Axios v0.27.2 to v1.1.2, I get an error in the following because response.error
now returns undefined
import axios from 'axios'
const axiosInstance = axios.create({ baseURL: 'http://localhost:8080' })
export default axiosInstance
// the definition of the functions saveNewToken, showError have been
// omitted in the interest of brevity
axiosInstance.interceptors.response.use(saveNewToken, error => {
// The error occurs here because error.response is undefined
switch (error.response.status) {
case 400:
showError(error.response.data, 'Validation error: please correct any errors before re-submitting')
break
}
return Promise.reject(error)
})
So I guess the response interceptors API changed such that error.response
is not a valid property of the argument passed to the onRejected
handler.
I've read through the Axios release notes and looked for a v1 migration guide for a list of required changes, but I can't find anything specific about API changes in v1.
Share asked Oct 14, 2022 at 11:43 Antonio DragosAntonio Dragos 2,9239 gold badges43 silver badges75 bronze badges 1-
I think it was
undefined
since the beginning , I have "^0.27.2" with typescript and it shows its as optional param (undefined). and if you see source ofaxios-0.x
it further confirms. – bogdanoff Commented Oct 14, 2022 at 12:18
1 Answer
Reset to default 3There are multiple issues submitted regarding error
s for 1.1.2
For example:
After upgrading form v0.27.2 to v1.1.2 import error with Vite
Build shows warning: Non-existent export 'AxiosError' is imported from node_modules/axios/index.js
https://github./axios/axios/issues/5118
And
Describe the bug AxiosHeaders, AxiosError, CanceledError and Axios are "exported" in the type definitions index.d.ts, but not exported in the module.
https://github./axios/axios/issues/5031
So I think your issue is related. It's maybe a good idea to wait for these issues get fixed.
本文标签: javascriptAxios error after upgrading from v0272 to v112Stack Overflow
版权声明:本文标题:javascript - Axios error after upgrading from v0.27.2 to v1.1.2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745014442a2637751.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论