From 1db53da0d397e174d74c3e39bd14542bc66d4572 Mon Sep 17 00:00:00 2001 From: Trotyl Yu Date: Sat, 17 Nov 2018 13:49:16 +0800 Subject: [PATCH] fix(common): expose request url in network error (#27143) closes #27029 PR Close #27143 --- packages/common/http/src/xhr.ts | 2 ++ packages/common/http/test/xhr_spec.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/common/http/src/xhr.ts b/packages/common/http/src/xhr.ts index c0a388dc94..9dc01058b6 100644 --- a/packages/common/http/src/xhr.ts +++ b/packages/common/http/src/xhr.ts @@ -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); }; diff --git a/packages/common/http/test/xhr_spec.ts b/packages/common/http/test/xhr_spec.ts index dfafef1df3..88e608d484 100644 --- a/packages/common/http/test/xhr_spec.ts +++ b/packages/common/http/test/xhr_spec.ts @@ -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'));