Error response with application/json body throws InvalidStateError
See original GitHub issueWhen I return a validation error message from my server as with content type application/json
with status code 400
this throws the following error:
Uncaught InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').
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…
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
HTTP error 400 in AJAX POST request - javascript
It looks much better, though it still throws back an error - InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The ...
Read more >HTTP status and error codes for JSON | Cloud Storage
Indicates an incomplete resumable upload and provides the range of bytes already received by Cloud Storage. Responses with this status do not contain...
Read more >XMLHttpRequest Standard
The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD . Throws an...
Read more >Payment Request API
This specification standardizes an API to allow merchants (i.e. web sites selling physical or digital goods) to utilize one or more payment ...
Read more >XMLHttpRequest.send() - Web APIs | MDN
Exceptions. InvalidStateError DOMException. Thrown if send() has already been invoked for the request, and/or the request is complete.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.)
I encounter similar problem @0.16.2. ajaxInject.js:1 Uncaught DOMException: Failed to read the ‘responseText’ property from ‘XMLHttpRequest’: The value is only accessible if the object’s ‘responseType’ is ‘’ or ‘text’ (was ‘blob’). Thank you for your help~