From 5a071401aade4fa5c1d3ef852a5861cb94475e73 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 6 Apr 2013 18:06:41 +0200 Subject: [PATCH] Error out more usefully from formparams when required parameters are missing. --- wrw/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wrw/util.py b/wrw/util.py index 55b4ee2..64b820f 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -1,5 +1,5 @@ import inspect -import req, dispatch, session, form +import req, dispatch, session, form, resp 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 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 -- 2.11.0