Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,14 @@ Server.prototype._finishReqResCycle = function _finishReqResCycle(
// after event has signature of function(req, res, route, err) {...}
self.emit('after', req, res, route, err || res.err);
} else {
// preserve error for actual finish
res.err = err;
// Store error for when the response is flushed and we actually emit the
// 'after' event. The "err" object passed to this method takes
// precedence, but in case it's not set, "res.err" may have been already
// set by another code path and we want to preserve it. The caveat thus
// is that the 'after' event will be emitted with the latest error that
// was set before the response is fully flushed. While not ideal, this
// is on purpose and accepted as a reasonable trade-off for now.
res.err = err || res.err;
}
};

Expand Down