Error out more usefully from formparams when required parameters are missing.
authorFredrik Tolf <fredrik@dolda2000.com>
Sat, 6 Apr 2013 16:06:41 +0000 (18:06 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Sat, 6 Apr 2013 16:06:41 +0000 (18:06 +0200)
wrw/util.py

index 55b4ee2..64b820f 100644 (file)
@@ -1,5 +1,5 @@
 import inspect
 import inspect
-import req, dispatch, session, form
+import req, dispatch, session, form, resp
 
 def wsgiwrap(callable):
     def wrapper(env, startreq):
 
 def wsgiwrap(callable):
     def wrapper(env, startreq):
@@ -16,6 +16,9 @@ def formparams(callable):
             for arg in list(args):
                 if arg not in spec.args:
                     del args[arg]
             for arg in list(args):
                 if arg not in spec.args:
                     del args[arg]
+        for i in xrange(len(spec.args) - len(spec.defaults)):
+            if spec.args[i] not in args:
+                raise resp.httperror(400, "Missing parameter", ("The query parameter `", resp.h.code(spec.args[i]), "' is required but not supplied."))
         return callable(**args)
     return wrapper
 
         return callable(**args)
     return wrapper