From 3ec0b7fb5dfb01f995c15ad71795f7211f444973 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 10 Apr 2019 15:39:36 -0400 Subject: [PATCH] isJsonResponse helper --- src/services/api.service.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 8b4acd2bd9..fcff0bf77d 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -166,8 +166,7 @@ export class ApiService implements ApiServiceAbstraction { })); let responseJson: any = null; - const typeHeader = response.headers.get('content-type'); - if (typeHeader != null && typeHeader.indexOf('application/json') > -1) { + if (this.isJsonResponse(response)) { responseJson = await response.json(); } @@ -932,8 +931,7 @@ export class ApiService implements ApiServiceAbstraction { } let responseJson: any = null; - const typeHeader = response.headers.get('content-type'); - if (typeHeader != null && typeHeader.indexOf('application/json') > -1) { + if (this.isJsonResponse(response)) { responseJson = await response.json(); } @@ -1001,4 +999,9 @@ export class ApiService implements ApiServiceAbstraction { } return base; } + + private isJsonResponse(response: Response): boolean { + const typeHeader = response.headers.get('content-type'); + return typeHeader != null && typeHeader.indexOf('application/json') > -1; + } }