Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

422 response not rejected #722

Closed
myarete opened this issue Feb 22, 2017 · 3 comments
Closed

422 response not rejected #722

myarete opened this issue Feb 22, 2017 · 3 comments

Comments

@myarete
Copy link

myarete commented Feb 22, 2017

We have a project that uses axios@0.14.0 (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));
      });
  };
}

Source code here

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!

@musbaig
Copy link

musbaig commented Feb 24, 2017

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.

@musbaig
Copy link

musbaig commented Feb 25, 2017

Never mind, found my problem. Interceptors weren't properly propagating errors down to the app layer, d'oh! 😳

@RickCarlino
Copy link

RickCarlino commented Mar 3, 2017

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);

@myarete myarete closed this as completed Mar 3, 2017
@myarete myarete reopened this Mar 3, 2017
@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants