Use xhr.onreadystatechange instead of xhr.onload (#1838)
This commit is contained in:
parent
2a71d18a6a
commit
5e38303377
|
|
@ -84,15 +84,22 @@ export class DefaultHttpClient extends HttpClient {
|
||||||
xhr.timeout = request.timeout;
|
xhr.timeout = request.timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
xhr.onload = () => {
|
xhr.onreadystatechange = () => {
|
||||||
if (request.abortSignal) {
|
if (xhr.readyState === 4) {
|
||||||
request.abortSignal.onabort = null;
|
if (request.abortSignal) {
|
||||||
}
|
request.abortSignal.onabort = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (xhr.status >= 200 && xhr.status < 300) {
|
// Some browsers report xhr.status == 0 when the
|
||||||
resolve(new HttpResponse(xhr.status, xhr.statusText, xhr.response || xhr.responseText));
|
// response has been cut off or there's been a TCP FIN.
|
||||||
} else {
|
// Treat it like a 200 with no response.
|
||||||
reject(new HttpError(xhr.statusText, xhr.status));
|
if (xhr.status === 0) {
|
||||||
|
resolve(new HttpResponse(200, null, null));
|
||||||
|
} else if (xhr.status >= 200 && xhr.status < 300) {
|
||||||
|
resolve(new HttpResponse(xhr.status, xhr.statusText, xhr.response || xhr.responseText));
|
||||||
|
} else {
|
||||||
|
reject(new HttpError(xhr.statusText, xhr.status));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue