Skip to content
Myr

Fix catching errors from top-level handlers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 253ce48 · Browse files · 3 files+29 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+29 added−6 removed

  • tests:+23 added−1 removed
  • other:+6 added−5 removed

3 files+29 added−6 removed

modified:lib/router/index.js+5 added-5 removed
243 unmodified lines
244 }245246 debug('%s %s : %s', layer.handle.name || 'anonymous', layerPath, req.originalUrl);247 var arity = layer.handle.length;248 if (err) {249 if (arity === 4) {248 try {249 if (err && arity === 4) {250 layer.handle(err, req, res, next);251 } else if (!err && arity < 4) {252 layer.handle(req, res, next);253 } else {254 next(err);255 }254 } else if (arity < 4) {255 layer.handle(req, res, next);256 } else {256 } catch (err) {257 next(err);258 }259 }260 }
175 unmodified lines
modified:test/Router.js+23 added-1 removed
127 unmodified lines
128 assert.equal(err.message, 'foo');129 done();130 });131132 router.handle({ url: '/foo/2', method: 'GET' }, {}, done);132 router.handle({ url: '/foo/2', method: 'GET' }, {}, function() {});133 });134135 it('should handle throwing in handler after async param', function(done) {136 var router = new Router();137138 router.param('user', function(req, res, next, val){139 process.nextTick(function(){140 req.user = val;141 next();142 });143 });144145 router.use('/:user', function(req, res, next){146 throw new Error('oh no!');147 });148149 router.use(function(err, req, res, next){150 assert.equal(err.message, 'oh no!');151 done();152 });153154 router.handle({ url: '/bob', method: 'GET' }, {}, function() {});155 });156157 it('should handle throwing inside error handlers', function(done) {158 var router = new Router();159160 router.use(function(req, res, next){
161 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * fix catching errors from top-level handlers5 * use `vary` module for `res.vary`6 * deps: proxy-addr@1.0.17 * deps: type-is@1.2.18 * deps: debug@1.0.0
1573 unmodified lines