Skip to content

Commit bc12ca3

Browse files
philjacksonindexzero
authored andcommitted
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.
1 parent 781c038 commit bc12ca3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/node-http-proxy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ exports.stack = function stack (middlewares, proxy) {
294294
handle = function (req, res) {
295295
var next = function (err) {
296296
if (err) {
297+
if (! proxy.emit('middlewareError', err, res, req)) {
298+
console.error('Error in middleware(s): %s', err.stack);
299+
}
300+
297301
if (res._headerSent) {
298302
res.destroy();
299303
}
@@ -303,7 +307,6 @@ exports.stack = function stack (middlewares, proxy) {
303307
res.end('Internal Server Error');
304308
}
305309

306-
console.error('Error in middleware(s): %s', err.stack);
307310
return;
308311
}
309312

0 commit comments

Comments
 (0)