From 0f436d5916807cde879617c85a5aea18b98ae1d4 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sat, 22 Sep 2012 15:22:15 +0200 Subject: [PATCH] Migrate error handling middleware to express v3 --- src/node/hooks/express/errorhandling.js | 26 +++++-------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/node/hooks/express/errorhandling.js b/src/node/hooks/express/errorhandling.js index 3c5727ed4..749b04273 100644 --- a/src/node/hooks/express/errorhandling.js +++ b/src/node/hooks/express/errorhandling.js @@ -32,31 +32,15 @@ exports.gracefulShutdown = function(err) { exports.expressCreateServer = function (hook_name, args, cb) { exports.app = args.app; - - -/* - Below breaks Express 3, commented out to allow express 3o to run. For mroe details see: - https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x -/* -/* - args.app.error(function(err, req, res, next){ - res.send(500); - console.error(err.stack ? err.stack : err.toString()); - exports.gracefulShutdown(); - }); -*/ - - - -// args.app.on('close', function(){ -// console.log("Exited in a sloppy fashion"); -// }) - + // Handle errors args.app.use(function(err, req, res, next){ // if an error occurs Connect will pass it down // through these "error-handling" middleware // allowing you to respond however you like - res.send(500, { error: 'Sorry something bad happened!' }); + res.send(500, { error: 'Sorry, something bad happened!' }); + console.error(err.stack? err.stack : err.toString()); + exports.gracefulShutdown(); + next(); })