Skip to content

Instantly share code, notes, and snippets.

@othiym23
Created June 18, 2013 18:54
Show Gist options
  • Save othiym23/5808172 to your computer and use it in GitHub Desktop.
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.
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