onResponse returns json even though the header might not be json
edgesoft opened this issue · comments
Mathias Nilsson commented
We need to look at the actual response to make sure it's not just text. If we make a request to an api endpoint that does not exists it returns a String and will be Uncaught SyntaxError when parsed as json.
Christian Alfoni commented
I believe I fixed that?
var result = xhr.responseText
if (xhr.getResponseHeader('content-type').indexOf('application/json') >= 0) {
result = JSON.parse(xhr.responseText)
}
:)