Revert "Use xhr.onreadystatechange instead of xhr.onload (#1838)" (#2065)

This reverts commit 5e38303377.
This commit is contained in:
Mikael Mengistu 2018-04-18 17:38:27 +00:00 committed by GitHub
parent 5c9b64244a
commit d9272032d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 15 deletions

View File

@ -94,22 +94,15 @@ export class DefaultHttpClient extends HttpClient {
xhr.timeout = request.timeout;
}
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (request.abortSignal) {
request.abortSignal.onabort = null;
}
xhr.onload = () => {
if (request.abortSignal) {
request.abortSignal.onabort = null;
}
// Some browsers report xhr.status == 0 when the
// response has been cut off or there's been a TCP FIN.
// Treat it like a 200 with no response.
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));
}
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));
}
};