We have a project that uses [email protected] (upgrading to 0.15.3 did not resolve the issue) in many parts of the application. In all of the other parts of the app, we're able to .catch()
422 response codes. Recently we noticed that 1 request is resolving a promise that gets a 422 response. In all other parts of our application, a 422 causes axios promises to be rejected.
export function addTool(name: string): Thunk {
return (dispatch, getState) => {
Axios
.post<Tool>(API.current.toolsPath, { name })
.then(resp => {
if (resp instanceof Error) { throw resp; }
success("Tool has been saved.", "Success");
dispatch(addToolOk(resp.data));
})
.catch((e: Error) => {
dispatch(addToolNo(e));
error(prettyPrintApiErrors(e));
});
};
}
I was able to work around the issue by adding the following line to my .then()
:
if (resp instanceof Error) { throw resp; }
Which works fine, but I'm still confused as to why this particular 422 is resolved (rather than rejected). We also have some interceptors in use, but they haven't cause any issues for the other requests we make.
Are there any circumstances in that would cause axios to resolve a 422 rather than reject it? Please let me know if you need any other information.
Thanks for the help!
Confirmed. I'm also seeing something similar when using axios with redux-saga
where some 422's aren't being handled as a rejected promise.
Never mind, found my problem. Interceptors weren't properly propagating errors down to the app layer, d'oh! 馃槼
After investigating this issue, I found that it was actually a local type error hidden deep in the call stack somewhere, leading me to believe that it is a local issue rather than a problem with Axios.
UPDATE:
After some investigation, I was able to pin this down to a bad "response rejected" interceptor.
Within the interceptor I wrote:
return error
and I solved the problem by instead writing:
return Promise.reject(error);
Most helpful comment
After investigating this issue, I found that it was actually a local type error hidden deep in the call stack somewhere, leading me to believe that it is a local issue rather than a problem with Axios.
UPDATE:
After some investigation, I was able to pin this down to a bad "response rejected" interceptor.
Within the interceptor I wrote:
and I solved the problem by instead writing: