diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index 956a5f3..c1275ab 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -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(); } @@ -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; }