-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Error response with application/json body throws InvalidStateError #171
Comments
I think this could be resolved by switching the order of the conditional check: (xDomain && request.responseText) This way we only reference |
Don't read responseText unless the responseType is either 'text', '' or undefined.
Don't read responseText unless the responseType is either 'text', '' or undefined/null.
Sorry I was doing something else, but had this fix commited on my fork already before I saw your comment. Not sure what you prefer, but you seemed to have the check already in place so I just thought I'd use it. |
I think it would be safer to do as I suggested above. Thanks for the PR! |
Fixing #171, don't fail on error responses with json payloads
A few minutes ago, I encountered same issue. but, is was already fixed. very nice! 👍 |
Hi, I'm using axios within a react + redux app and I'm getting same error when a request that expects a JSON result fails with a 400 error:
Is the issue re-opened? |
I just encountered the same problem. (Edit: I redact my request to reopen this. I was seeing an error from another package that was reported in such a way that it looked like there was an issue with the way axios was handling api responses.) |
If you use redux-axios-middleware just take a look at this issue |
I encounter similar problem @0.16.2. |
When I return a validation error message from my server as with content type
application/json
with status code400
this throws the following error:on this line: https://github.com/mzabriskie/axios/blob/f9c46c5c1da731c150febd347708f229e9bc74ab/lib/adapters/xhr.js#L75. Apparently it's not allowed to access the responseText property if the responseType does not match '' or 'text'.
You seem to be aware of this since you are checking exactly this a few lines earlier (https://github.com/mzabriskie/axios/blob/f9c46c5c1da731c150febd347708f229e9bc74ab/lib/adapters/xhr.js#L62).
I'd submit a pull request, but I'm not entirely sure what case is meant by the
(request.responseText && xDomain)
code...The text was updated successfully, but these errors were encountered: