Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix: don't wrap non-functions. (Issue #1)

  • Loading branch information...
commit 3982548744ba7cf3b26938fa995e06fc4ba3a8e9 1 parent 05c797d
@aseemk authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 index.js
View
12 index.js
@@ -29,10 +29,16 @@ var verbs = ['all', 'get', 'post', 'put', 'del', 'error'];
function patch(verb) {
var origAppVerb = app[verb];
app[verb] = function () {
- // wrap the handler function, which is the last argument:
+ // if a handler function is given, it'll be the last argument:
var last = arguments.length - 1;
- arguments[last] = wrap(arguments[last]);
- // then call the original verb with this wrapped handler:
+ var lastArg = arguments[last];
+
+ // if there is one, wrap it:
+ if (typeof lastArg === 'function') {
+ arguments[last] = wrap(lastArg);
+ }
+
+ // finally, call the original method now with the updated args:
origAppVerb.apply(this, arguments);
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.