Skip to content

Commit d0ddc8c

Browse files
committed
handle JSON parse errors
1 parent 81e89bc commit d0ddc8c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/index.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ var HTTPSnippet = function (req, lang) {
4949

5050
case 'application/json':
5151
if (this.source.postData.text) {
52-
this.source.postData.jsonObj = JSON.parse(this.source.postData.text);
52+
try {
53+
this.source.postData.jsonObj = JSON.parse(this.source.postData.text);
54+
} catch (e) {
55+
debug(e);
56+
57+
// force back to plain/text
58+
// if headers have proper content-type value, then this should also work
59+
this.source.postData.mimeType = 'plain/text'
60+
}
5361
}
5462
break;
5563
}

0 commit comments

Comments
 (0)