From 603f251824b55be022023633333b215cc996e4b9 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Wed, 12 Sep 2012 19:34:33 +0100 Subject: [PATCH] error handling and close is removed in express 3 --- src/node/hooks/express/errorhandling.js | 25 ++++++++++++++++++++++--- src/package.json | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/node/hooks/express/errorhandling.js b/src/node/hooks/express/errorhandling.js index cb8c5898..3c5727ed 100644 --- a/src/node/hooks/express/errorhandling.js +++ b/src/node/hooks/express/errorhandling.js @@ -16,9 +16,6 @@ exports.gracefulShutdown = function(err) { console.log("graceful shutdown..."); - //stop the http server - exports.app.close(); - //do the db shutdown db.db.doShutdown(function() { console.log("db sucessfully closed."); @@ -35,11 +32,33 @@ 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"); +// }) + + 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!' }); + }) + //connect graceful shutdown with sigint and uncaughtexception if(os.type().indexOf("Windows") == -1) { diff --git a/src/package.json b/src/package.json index a2fc147a..a7550fae 100644 --- a/src/package.json +++ b/src/package.json @@ -17,7 +17,7 @@ "socket.io" : "0.9.x", "ueberDB" : "0.1.7", "async" : "0.1.x", - "express" : "2.5.x", + "express" : "3.x", "connect" : "1.x", "clean-css" : "0.3.2", "uglify-js" : "1.2.5",