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

[Restify 7] Fix uncaught exceptions triggering route lookups #1717

Merged
merged 3 commits into from Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions lib/server.js
Expand Up @@ -1077,7 +1077,7 @@ Server.prototype._onHandlerError = function _onHandlerError(
var self = this;

// Call route by name
if (_.isString(err)) {
if (!isUncaught && _.isString(err)) {
var routeName = err;
var routeHandler = self.router.lookupByName(routeName, req, res);

Expand Down Expand Up @@ -1482,9 +1482,10 @@ function errEvtNameFromError(err) {
} else if (err.name === 'InvalidVersionError') {
// remap the name for router errors
return 'VersionNotAllowed';
} else {
hekike marked this conversation as resolved.
Show resolved Hide resolved
} else if (err.name) {
return err.name.replace(/Error$/, '');
}
return '';
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/server.test.js
Expand Up @@ -2477,6 +2477,36 @@ test('should emit error with multiple next calls with strictNext', function(t) {
});
});

test('uncaughtException should not trigger named routeHandler', function(t) {
SERVER.get(
{
name: 'foo',
path: '/foo'
},
function(req, res, next) {
throw 'bar'; //eslint-disable-line no-throw-literal
}
);

SERVER.get(
{
name: 'bar',
path: '/bar'
},
function(req, res, next) {
// This code should not run, but we can test against the status code
hekike marked this conversation as resolved.
Show resolved Hide resolved
res.send(200);
next();
}
);

CLIENT.get('/foo', function(err, _, res) {
t.ok(err);
t.equal(res.statusCode, 500);
t.end();
});
});

test('should have proxy event handlers as instance', function(t) {
var server = restify.createServer({
handleUpgrades: false
Expand Down