From 3f322af7bed25bb6f2d702d0f5d8cc300492ded6 Mon Sep 17 00:00:00 2001 From: frederic Ginioux <158451115+fginioux-golding@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:05:26 +0100 Subject: [PATCH] fix: wrap success return into try catch to avoid server side fatal error When we are running the script and the R code throw an error the close callback is called with non parsable body and crash the node js application. To "gracefully" handle the error the proposition is to wrap the code into a try/catch and return the error instead of the body ; --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index db6101c..bb19cc2 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,11 @@ R.prototype.call = function(_opts, _callback) { body += d; }); child.on("close", function(code) { - callback(null, JSON.parse(body)); + try { + callback(null, JSON.parse(body)); + } catch(err) { + callback(err, null); + } }); };