From e57fd1e96e6fa2ed95e2d76aa6723394c44768ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20Kr=C3=B6mer?= Date: Fri, 19 Jul 2019 11:52:35 +0200 Subject: [PATCH] Do not try to parse JSON if response body is empty. Otherwise JSON.parse throws "SyntaxError: Unexpected end of JSON input" which result in ommited HTTP response headers. Firefox and Chrome do not ommit the headers when doing the same XMLHttpRequest. Sending an empty body with JSON as content type is not wrong in my option when doing a POST returning a 201 (e.g. Created) with a proper Location header leading to the created resource as JSON. --- tns-core-modules/xhr/xhr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tns-core-modules/xhr/xhr.ts b/tns-core-modules/xhr/xhr.ts index 24430c65da..00dacf98db 100644 --- a/tns-core-modules/xhr/xhr.ts +++ b/tns-core-modules/xhr/xhr.ts @@ -107,7 +107,7 @@ export class XMLHttpRequest { this._addToStringOnResponse(); if (this.responseType === XMLHttpRequestResponseType.json) { - this._response = JSON.parse(this.responseText); + this._response = this.responseText.length ? JSON.parse(this.responseText) : this.responseText; } else if (this.responseType === XMLHttpRequestResponseType.text) { this._response = this.responseText; }