diff --git a/modules/common/clover/src/transfer-http-cache/transfer-http-cache.interceptor.ts b/modules/common/clover/src/transfer-http-cache/transfer-http-cache.interceptor.ts index 51008acd1..8c9916503 100644 --- a/modules/common/clover/src/transfer-http-cache/transfer-http-cache.interceptor.ts +++ b/modules/common/clover/src/transfer-http-cache/transfer-http-cache.interceptor.ts @@ -22,8 +22,8 @@ import { filter, take, tap } from 'rxjs/operators'; type ResponseType = HttpRequest['responseType']; interface TransferHttpResponse { - body?: any | null; - headers?: Record; + body: any; + headers: Record; status?: number; statusText?: string; url?: string; @@ -74,10 +74,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor { if (this.transferState.hasKey(storeKey)) { // Request found in cache. Respond using it. - const response = this.transferState.get(storeKey, {}); - let body: ArrayBuffer | Blob | string | undefined = response.body; + const response = this.transferState.get(storeKey, null); + let body: ArrayBuffer | Blob | string | undefined = response?.body; - switch (response.responseType) { + switch (response?.responseType) { case 'arraybuffer': { // If we're in Node... @@ -102,10 +102,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor { return of( new HttpResponse({ body, - headers: new HttpHeaders(response.headers), - status: response.status, - statusText: response.statusText, - url: response.url, + headers: new HttpHeaders(response?.headers), + status: response?.status, + statusText: response?.statusText, + url: response?.url, }), ); } diff --git a/modules/common/src/transfer_http.ts b/modules/common/src/transfer_http.ts index 9cc346daa..18e3d96f9 100644 --- a/modules/common/src/transfer_http.ts +++ b/modules/common/src/transfer_http.ts @@ -29,9 +29,9 @@ import { defaultIfEmpty, first, tap } from 'rxjs/operators'; type ResponseType = HttpRequest['responseType']; -export interface TransferHttpResponse { - body?: any | null; - headers?: Record; +interface TransferHttpResponse { + body: any; + headers: Record; status?: number; statusText?: string; url?: string; @@ -96,10 +96,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor { if (this.transferState.hasKey(storeKey)) { // Request found in cache. Respond using it. - const response = this.transferState.get(storeKey, {}); - let body: ArrayBuffer | Blob | string | undefined = response.body; + const response = this.transferState.get(storeKey, null); + let body: ArrayBuffer | Blob | string | undefined = response?.body; - switch (response.responseType) { + switch (response?.responseType) { case 'arraybuffer': body = new TextEncoder().encode(response.body).buffer; break; @@ -111,10 +111,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor { return observableOf( new HttpResponse({ body, - headers: new HttpHeaders(response.headers), - status: response.status, - statusText: response.statusText, - url: response.url, + headers: new HttpHeaders(response?.headers), + status: response?.status, + statusText: response?.statusText, + url: response?.url, }), ); } else {