-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
Describe the bug
The documentation states:
// `responseType` indicates the type of data that the server will respond with
// options are: 'arraybuffer', 'document', 'json', 'text', 'stream'
// browser only: 'blob'
responseType: 'json', // default
However, the responseType of XMLHttpRequest is left unset (same as "text") by default instead of being set set to 'json'. This causes an empty response body to become "" instead of null as expected from the XMLHttpRequest specification :
A JSON response is the return value of these steps:
- If response’s body is null, then return null.
- Let jsonObject be the result of running parse JSON from bytes on received bytes. If that threw an exception, then return null.
- Set response object to jsonObject and return it.
A text response is the return value of these steps:
- If response’s body is null, then return the empty string.
To Reproduce
Create a request with the XHR adapter where the server responds with an empty body. Then response.data === "".
Expected behavior
response.data === null (through a default request.responseType = 'json').
Environment
- Axios Version: 0.19.2
- Adapter: XHR
- Browser: Chrome
- Browser Version: 83
- OS: Windows 10
Additional context/Screenshots
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels