Fix request.responseBody not defined
mtscrb opened this issue · 0 comments
mtscrb commented
Related to #163
In nativeSend
, the request.responseBody
sometimes it's undefined
, when the responseType
is empty.
Refer to https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
We need to have a fallback to either responseText
or response
based on the responseType.
Something like
const response = new _Response.Response(request.status, request.responseBody || request.responseText || request.response, headers);
Also, in _handleResponse
we are stringifying the response without checking the responseType
We should do something like:
if (this.responseType === "blob") {
if (body instanceof Blob) {
this._response = body;
} else {
this._response = new Blob([body]);
}
} else if (this.responseType === "json") {
this._response = JSON.stringify(body);
} else {
this._response = body;
}