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 // Connection timeout, DNS error, offline, etc. These are actual errors, and are
// transmitted on the error channel. // transmitted on the error channel.
const onError = (error: ErrorEvent) => { const onError = (error: ErrorEvent) => {
const {url} = partialFromXhr();
const res = new HttpErrorResponse({ const res = new HttpErrorResponse({
error, error,
status: xhr.status || 0, status: xhr.status || 0,
statusText: xhr.statusText || 'Unknown Error', statusText: xhr.statusText || 'Unknown Error',
url: url || undefined,
}); });
observer.error(res); observer.error(res);
}; };

View File

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