question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error response with application/json body throws InvalidStateError

See original GitHub issue

When 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:closed
  • Created 8 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
GerryFuddcommented, Jan 5, 2017

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

0reactions
qttttttttttingcommented, Dec 19, 2018

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~

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found