Skip to content

Commit

Permalink
Emit middlewareError when on middleware error.
Browse files Browse the repository at this point in the history
Now it's possible to pass an Error object to next() and have it handled
in a custom way that's suitable to your application.
  • Loading branch information
philjackson authored and indexzero committed Dec 27, 2013
1 parent 781c038 commit bc12ca3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/node-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ exports.stack = function stack (middlewares, proxy) {
handle = function (req, res) {
var next = function (err) {
if (err) {
if (! proxy.emit('middlewareError', err, res, req)) {
console.error('Error in middleware(s): %s', err.stack);
}

if (res._headerSent) {
res.destroy();
}
Expand All @@ -303,7 +307,6 @@ exports.stack = function stack (middlewares, proxy) {
res.end('Internal Server Error');
}

console.error('Error in middleware(s): %s', err.stack);
return;
}

Expand Down

0 comments on commit bc12ca3

Please sign in to comment.