From e1ba6fa1ab369f5ec83fcbaa8f676e17198a142a Mon Sep 17 00:00:00 2001 From: Jan Nino Walter Date: Wed, 28 Feb 2024 13:31:11 +0100 Subject: [PATCH] Don't throw exception if json parsing fails, instead return unparsed data --- core/src/core-plugins.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/core-plugins.ts b/core/src/core-plugins.ts index 7ec429f7c5..60cc5c2db8 100644 --- a/core/src/core-plugins.ts +++ b/core/src/core-plugins.ts @@ -385,6 +385,7 @@ export class CapacitorHttpPluginWeb let data: any; let blob: any; + let responseText: string; switch (responseType) { case 'arraybuffer': case 'blob': @@ -392,7 +393,12 @@ export class CapacitorHttpPluginWeb data = await readBlobAsBase64(blob); break; case 'json': - data = await response.json(); + responseText = await response.text(); + try { + data = JSON.parse(responseText); + } catch (e) { + data = responseText; + } break; case 'document': case 'text':