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; + } }