fix(common): expose request url in network error (#27143)

closes #27029

PR Close #27143
This commit is contained in:
Trotyl Yu 2018-11-17 13:49:16 +08:00 committed by Jason Aden
parent f45aedcbf0
commit 1db53da0d3
2 changed files with 3 additions and 0 deletions

View File

@ -232,10 +232,12 @@ export class HttpXhrBackend implements HttpBackend {
// Connection timeout, DNS error, offline, etc. These are actual errors, and are
// transmitted on the error channel.
const onError = (error: ErrorEvent) => {
const {url} = partialFromXhr();
const res = new HttpErrorResponse({
error,
status: xhr.status || 0,
statusText: xhr.statusText || 'Unknown Error',
url: url || undefined,
});
observer.error(res);
};

View File

@ -142,6 +142,7 @@ const XSSI_PREFIX = ')]}\'\n';
backend.handle(TEST_POST).subscribe(undefined, (err: HttpErrorResponse) => {
expect(err instanceof HttpErrorResponse).toBe(true);
expect(err.error instanceof Error);
expect(err.url).toBe('/test');
done();
});
factory.mock.mockErrorEvent(new Error('blah'));