Migrate error handling middleware to express v3

pull/1020/head
Marcel Klehr 2012-09-22 15:22:15 +02:00
parent 794c3d1afe
commit 0f436d5916
1 changed files with 5 additions and 21 deletions

View File

@ -32,31 +32,15 @@ exports.gracefulShutdown = function(err) {
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = function (hook_name, args, cb) {
exports.app = args.app; exports.app = args.app;
// Handle errors
/*
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){ args.app.use(function(err, req, res, next){
// if an error occurs Connect will pass it down // if an error occurs Connect will pass it down
// through these "error-handling" middleware // through these "error-handling" middleware
// allowing you to respond however you like // 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();
}) })