Skip to content
Browse files

change router callback check error message

to read:

Error: .get() requires callback functions but got a [object String]
  • Loading branch information...
1 parent 618484a commit 8d21f1e45c5149600b7eb00734a7eee6e90677a8 @tj tj committed
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/router/index.js
View
10 lib/router/index.js
@@ -16,7 +16,7 @@ exports = module.exports = Router;
/**
* Initialize a new `Router` with the given `options`.
- *
+ *
* @param {Object} options
* @api private
*/
@@ -140,7 +140,7 @@ Router.prototype._dispatch = function(req, res, next){
};
param(err);
-
+
// single param callbacks
function paramCallback(err) {
var fn = paramCallbacks[paramIndex++];
@@ -245,9 +245,11 @@ Router.prototype.route = function(method, path, callbacks){
if (!path) throw new Error('Router#' + method + '() requires a path');
// ensure all callbacks are functions
- callbacks.forEach(function(fn){
+ callbacks.forEach(function(fn, i){
if ('function' == typeof fn) return;
- throw new Error('Router#' + method + '() requires all callbacks to be functions');
+ var type = {}.toString.call(fn);
+ var msg = '.' + method + '() requires callback functions but got a ' + type;
+ throw new Error(msg);
});
// create the route

0 comments on commit 8d21f1e

Please sign in to comment.
Something went wrong with that request. Please try again.