From 83c995e019711785c416c71079916f59abce8dcd Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Sat, 29 Oct 2016 20:39:33 -0700 Subject: [PATCH] Don't crash on user function exceptions --- function-run/nodejs/server.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/function-run/nodejs/server.js b/function-run/nodejs/server.js index ec426c69..e8141f9e 100644 --- a/function-run/nodejs/server.js +++ b/function-run/nodejs/server.js @@ -10,8 +10,8 @@ const morgan = require('morgan'); // Command line opts const argv = require('minimist')(process.argv.slice(1)); if (!argv.codepath) { - console.log("Codepath defaulting to /user.js"); - argv.codepath = "/user.js"; + argv.codepath = "/userfunc/user"; + console.log("Codepath defaulting to ", argv.codepath); } if (!argv.port) { console.log("Port defaulting to 8888"); @@ -79,7 +79,11 @@ app.all('/', function (req, res) { } res.status(status).send(body); } - userFunction(context, callback); + try { + userFunction(context, callback); + } catch(e) { + callback(500, "Internal server error") + } }); app.listen(argv.port);