From cb1fbce46b078dff2da0aab4dcf1d3c2ce840e24 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Sun, 23 Mar 2014 14:42:46 -0400 Subject: [PATCH] don't call done twice for thrown errors inside parameterized routes fixes #1995 --- lib/router/index.js | 2 +- test/Router.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/router/index.js b/lib/router/index.js index 74183e20..e41f5f1f 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -280,7 +280,7 @@ proto.process_params = function(route, req, res, done) { return param(); } } catch (err) { - done(err); + return done(err); } done(); diff --git a/test/Router.js b/test/Router.js index c2058c5b..55f6bcff 100644 --- a/test/Router.js +++ b/test/Router.js @@ -111,6 +111,25 @@ describe('Router', function(){ router.handle({ url: '/foo', method: 'GET' }, {}, done); }); + + it('should handle throwing inside routes with params', function(done) { + var router = new Router(); + + router.get('/foo/:id', function(req, res, next){ + throw new Error('foo'); + }); + + router.use(function(req, res, next){ + assert(false); + }); + + router.use(function(err, req, res, next){ + assert.equal(err.message, 'foo'); + done(); + }); + + router.handle({ url: '/foo/2', method: 'GET' }, {}, done); + }); }) describe('.all', function() {