Permalink
Browse files

Improve RPC responder error checking. Thanks Petri

  • Loading branch information...
1 parent 3ef2759 commit 2226f07d5b1091b822b7e482568e2a3e93fcb967 Owen Barnes committed Jul 25, 2012
Showing with 10 additions and 0 deletions.
  1. +6 −0 lib/request/responders/rpc/request.js
  2. +4 −0 src/request/responders/rpc/request.coffee
View
6 lib/request/responders/rpc/request.js
@@ -11,6 +11,12 @@ module.exports = function(ss, middleware) {
api = apiTree.createApiTree(dir);
return request = function(req, res) {
var actions, cb, exec, file, main, methodAry, methodName, stack;
+ if (!(req.method && typeof req.method === 'string' && req.method.indexOf('.') > 0)) {
+ throw new Error("No action provided. Action names must be a string separated by dots/periods (e.g. 'message.send')");
+ }
+ if (!(req.params && req.params instanceof Array)) {
+ throw new Error("Params must be supplied as an Array");
+ }
stack = [];
req.use = function(nameOrModule) {
var args, fn, middlewareAry, mw;
View
4 src/request/responders/rpc/request.coffee
@@ -13,6 +13,10 @@ module.exports = (ss, middleware) ->
api = apiTree.createApiTree(dir)
request = (req, res) ->
+
+ # Initial error checking
+ throw new Error("No action provided. Action names must be a string separated by dots/periods (e.g. 'message.send')") unless req.method && typeof(req.method) == 'string' && req.method.indexOf('.') > 0
+ throw new Error("Params must be supplied as an Array") unless req.params && req.params instanceof Array
# Init request stack
stack = []

0 comments on commit 2226f07

Please sign in to comment.