From bc12ca39394f9aeed3e3047f59035ba48afa2885 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 10 Sep 2013 15:16:06 +0100 Subject: [PATCH] Emit middlewareError when on middleware error. 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. --- lib/node-http-proxy.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index 956a5f3d3..c1275ab39 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; }