Skip to content

Commit

Permalink
handle path-not-routed errors with the configured mw; 0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasq committed Mar 31, 2021
1 parent e3b44ec commit b75b462
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ tests or benchmarks, check out the repo from https://github.com/andrasq/node-mic
Change Log
----------

- 0.9.1 - pretty-print error responses, handle path-not-routed errors with the configured mw
- 0.9.0 - have parseQuery also set `req.path` and `req.query`
- 0.8.3 - speed access to req.params et al, req.destroy() if bodySizeLimit exceeded
- 0.8.2 - fix HttpError message text, mw.buildDecodeBody
Expand Down
2 changes: 1 addition & 1 deletion router.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Router.prototype.runRoute = function runRoute( rest, req, res, callback ) {
// route if not already routed
if (!ctx.req._route) {
ctx.req._route = ctx.self.getRoute(ctx.req.url, ctx.req.method);
if (!ctx.req._route) return ctx.callback(ctx.self.HttpError(ctx.self.NotRoutedHttpCode, ctx.req.method + ' ' + ctx.req.url + ': path not routed'));
if (!ctx.req._route) return runErrorRoute(ctx.self.HttpError(ctx.self.NotRoutedHttpCode, ctx.req.method + ' ' + ctx.req.url + ': path not routed'), ctx);
if (ctx.req._route.params) { ctx.req.params = ctx.req.params || {}; for (var k in ctx.req._route.params) ctx.req.params[k] = ctx.req._route.params[k]; }
}
// read body if not already read
Expand Down
10 changes: 10 additions & 0 deletions test-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ module.exports = {
t.done();
})
},

'should run post step after not-routed error': function(t) {
this.installRoutes();
var calls = this.calls;
this.req.url = '/not_routed_path';
this.router.runRoute({}, this.req, {}, function(err) {
t.contains(calls, ['err1', 'err2', 'post1', 'post2']);
t.done();
})
},
},

'mw exceptions': {
Expand Down

0 comments on commit b75b462

Please sign in to comment.