Skip to content

Commit

Permalink
ignore potentially incorrect JSON in request body (#46, #55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jozsefsallai committed May 21, 2021
1 parent a0ed5dd commit dd0d489
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit dd0d489

Please sign in to comment.