Skip to content

Commit 5e38303

Browse files
authored
Use xhr.onreadystatechange instead of xhr.onload (#1838)
1 parent 2a71d18 commit 5e38303

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

clients/ts/signalr/src/HttpClient.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,22 @@ export class DefaultHttpClient extends HttpClient {
8484
xhr.timeout = request.timeout;
8585
}
8686

87-
xhr.onload = () => {
88-
if (request.abortSignal) {
89-
request.abortSignal.onabort = null;
90-
}
91-
92-
if (xhr.status >= 200 && xhr.status < 300) {
93-
resolve(new HttpResponse(xhr.status, xhr.statusText, xhr.response || xhr.responseText));
94-
} else {
95-
reject(new HttpError(xhr.statusText, xhr.status));
87+
xhr.onreadystatechange = () => {
88+
if (xhr.readyState === 4) {
89+
if (request.abortSignal) {
90+
request.abortSignal.onabort = null;
91+
}
92+
93+
// Some browsers report xhr.status == 0 when the
94+
// response has been cut off or there's been a TCP FIN.
95+
// Treat it like a 200 with no response.
96+
if (xhr.status === 0) {
97+
resolve(new HttpResponse(200, null, null));
98+
} else if (xhr.status >= 200 && xhr.status < 300) {
99+
resolve(new HttpResponse(xhr.status, xhr.statusText, xhr.response || xhr.responseText));
100+
} else {
101+
reject(new HttpError(xhr.statusText, xhr.status));
102+
}
96103
}
97104
};
98105

0 commit comments

Comments
 (0)