Reputation: 2863
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.
Upvotes: 2
Views: 10241
Reputation: 36770
There 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.com/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.com/axios/axios/issues/5031
So I think your issue is related. It's maybe a good idea to wait for these issues get fixed.
Upvotes: 3