fengmk2/domain-middleware — pull request #1 by lefnire (2014-02-06 08:30:03+00:00)
Title: Add d to res.locals so can be accessed elsewhere

Our app is using and express error-handler middleware `function(err,req,res,next)` to shoot of emails, trigger New Relic error event, `res.json(500,..)`, etc. However, as a result, errors (even thrown) are handled there, and not caught by `d.on('error')` - and we don't get the worker restart goodies this module provides. The way I'm getting around it presently is adding `res.locals.domain=d;` (this commit), and in our error-handler calling `res.locals.domain.emit('error', err);`. There a better way about this?