From dd0d48909e09b255c2b6df298366c50de8f671c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Sallai?= Date: Fri, 21 May 2021 23:29:15 +0300 Subject: [PATCH] ignore potentially incorrect JSON in request body (#46, #55) --- src/lib/content.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/content.js b/src/lib/content.js index 1b7c344..451b3bd 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -13,7 +13,14 @@ class BodyParser { } this.body.text = this.body.text.replace(new RegExp('{{.*}}', 'g'), '"!!Missing declaration in environment!!"'); - const text = JSON.stringify(JSON.parse(this.body.text), null, 2); + let text; + + try { + text = JSON.stringify(JSON.parse(this.body.text), null, 2); + } catch (_) { + console.warn('Failed to parse JSON body (expect incorrect tokenization):', this.body.text); + text = this.body.text; + } return { type: 'plain',