Skip to content

Commit 9e2490b

Browse files
committed
account for the case when the Java backend returns something bogus
1 parent 60ba0b0 commit 9e2490b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎v4-cokapi/cokapi.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ function postExecHandler(res, useJSONP, err, stdout, stderr) {
8282
}
8383
} else {
8484
if (useJSONP) {
85-
// stdout better be real JSON!!!
86-
res.jsonp(JSON.parse(stdout) /* return an actual object, not a string */);
85+
try {
86+
// stdout better be real JSON, or we've got a problem!!!
87+
var stdoutParsed = JSON.parse(stdout);
88+
res.jsonp(stdoutParsed /* return an actual object, not a string */);
89+
} catch(e) {
90+
errTrace = {code: '', trace: [{'event': 'uncaught_exception',
91+
'exception_msg': "Unknown error. Report a bug to philip@pgbovine.net by clicking on the\n'Generate URL' button at the bottom and including a URL in your email."}]};
92+
res.jsonp(errTrace /* return an actual object, not a string */);
93+
}
8794
} else {
8895
res.send(stdout);
8996
}

0 commit comments

Comments
 (0)