Skip to content

Commit

Permalink
fix(server): prevent double error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Nov 15, 2017
1 parent 7b7df7d commit e315641
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/response.js
Expand Up @@ -346,6 +346,8 @@ function patch(Response) {
var log = self.log;
var code, body, headers, format;

self._sent = true;

// derive arguments from types, one by one
var index = 0;
// Check to see if the first argument is a status code
Expand Down Expand Up @@ -832,7 +834,7 @@ function flush(res, formattedBody) {
res.write(res._data);
}

// Finish resuest
// Finish request
res.end();

// If log level is set to trace, log the entire response object
Expand Down
5 changes: 5 additions & 0 deletions lib/server.js
Expand Up @@ -1103,6 +1103,11 @@ Server.prototype._routeErrorResponse = function _routeErrorResponse(
}

self._emitErrorEvents(req, res, null, err, function emitError(emitErr) {
// Prevent double handling
if (res._sent) {
return;
}

// Expose only knonw errors
if (_.isNumber(err.statusCode)) {
res.send(err);
Expand Down

0 comments on commit e315641

Please sign in to comment.