Open
Description
It seems to me that the Content-type
of a response is handled incorrectly. For example, if I create a request sending JSON data:
var options = {
...
contentType: 'application/json',
type: 'json',
...
};
var req = reqwest(options);
but the server responds with anything else (e.g. application/pdf
) then Reqwest still attempts to decode the response body as JSON. Looking at the code, the culprit seems to be the success()
function:
function success (resp) {
var type = o['type'] || resp && setType(resp.getResponseHeader('Content-Type')) // resp can be undefined in IE
...
here, o['type']
picks the content type of the request, thus prioritizing it over the content type of the response. Further down, this causes the mentioned attempt to decode as JSON what is not JSON.
As a fix, I’d propose to either swap the two sides of the ||
operator, or to completely remove the o['type']
.
Metadata
Metadata
Assignees
Labels
No labels