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: properly handle non-errors thrown in domains #1757
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1309,13 +1309,19 @@ Server.prototype._routeErrorResponse = function _routeErrorResponse( | |
return; | ||
} | ||
|
||
// Expose only knonw errors | ||
if (_.isNumber(err.statusCode)) { | ||
// only automatically send errors that are known (e.g., restify-errors) | ||
if (err && _.isNumber(err.statusCode)) { | ||
res.send(err); | ||
return; | ||
} | ||
|
||
res.send(new errors.InternalError(emitErr || err)); | ||
var finalErr = emitErr || err; | ||
if (!(finalErr instanceof Error)) { | ||
// if user land domain threw a string or number or any other | ||
// non-error object, handle it here as best we can. | ||
finalErr = (finalErr && finalErr.toString()) || ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this behave if |
||
} | ||
res.send(new errors.InternalError(finalErr)); | ||
}); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2505,9 +2505,10 @@ test('uncaughtException should handle thrown undefined literal', function(t) { | |
} | ||
); | ||
|
||
CLIENT.get('/foo', function(err, _, res) { | ||
CLIENT.get('/foo', function(err, _, res, data) { | ||
t.ok(err); | ||
t.equal(res.statusCode, 500); | ||
t.equal(data.message, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could technically send There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well if you do |
||
t.end(); | ||
}); | ||
}); | ||
|
@@ -2535,8 +2536,9 @@ test('uncaughtException should handle thrown Number', function(t) { | |
} | ||
); | ||
|
||
CLIENT.get('/foo', function(err, _, res) { | ||
CLIENT.get('/foo', function(err, _, res, data) { | ||
t.ok(err); | ||
t.equal(data.message, '1'); | ||
t.equal(res.statusCode, 500); | ||
t.end(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be followed for
throw res;
, don't know if we want to guard against that.