Axios 400 error request call then instead of catch
I found the solution
Problem caused by dont return promise in axios interceptors:
axios.interceptors.response.use((response) => { return response;}, (error) => { if (!error.response) { alert('NETWORK ERROR') } else { const code = error.response.status const response = error.response.data const originalRequest = error.config; if (code === 401 && !originalRequest._retry) { originalRequest._retry = true auth.commit('logout'); window.location.href = "/login"; } return Promise.reject(error) }});
adding return Promise.reject(error)
works like a charm
This is on purpose in older version of Axios.
validateStatus
has been added into config since v0.11. We can use this option to specify valid status code range. By default, valid code is >= 200 and < 300.
validateStatus: function (status) { return status >= 200 && status < 300; // default},
Ref: https://github.com/axios/axios/issues/41#issuecomment-215100137
Add a response interceptor like
axios.interceptors.response.use(function (response) { // Any status code that lie within the range of 2xx cause this function to trigger // Do something with response data return response; }, function (error) { // Any status codes that falls outside the range of 2xx cause this function to trigger // Do something with response error return Promise.reject(error); });