Created
June 18, 2013 18:54
-
-
Save othiym23/5808172 to your computer and use it in GitHub Desktop.
Simple way to put an error on a domain if one is available, and use the default Express error handler otherwise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var domain = require("domain"); | |
var defaultHandler = require("express").errorHandler(); | |
module.exports = function errorHandler(err, req, res, next) { | |
if (domain.active) { | |
domain.active.emit("error", err); | |
} | |
else { | |
return defaultHandler(err, req, res, next); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment