Skip to content
Myr

add better error messages for non-functions as middleware

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

Only functions are supported for [VERB](path, fn), use(path, fn) and all(fn) calls in Router and Routes. This catches those errors earlier to avoid checks during actual request processing.

authored by Roman Shtylman · committed by Roman Shtylman · parent 7693aa5 · Browse files · 2 files+12 added−0 removed
This commit

State

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

Diff stats

2 files+12 added−0 removed

  • other:+12 added−0 removed

2 files+12 added−0 removed

modified:lib/router/index.js+6 added
320 unmodified lines
321 fn = route;322 route = '/';323 }324325 if (typeof fn !== 'function') {326 var type = {}.toString.call(fn);327 var msg = 'Router.use() requires callback functions but got a ' + type;328 throw new Error(msg);329 }330331 // strip trailing slash332 if ('/' == route[route.length - 1]) {333 route = route.slice(0, -1);334 }
68 unmodified lines
modified:lib/router/route.js+6 added