Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit after event with proper error param for node versions >= 11.4.0 #1732

Merged
merged 2 commits into from Jan 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/server.js
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