From 526725fc248d42f95aba2de57d78b6074f4b9f7d Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 3 Jun 2018 12:50:51 +0200 Subject: [PATCH] Bugfix --- app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index a9751ad..aab54f9 100644 --- a/app.py +++ b/app.py @@ -757,7 +757,7 @@ def api_user_key(): return flask_jsonify(api_key=ADMIN_API_KEY) -def _user_api_arg(key: str) -> str: +def _user_api_arg(key: str, **kwargs: Dict[str, Any]) -> str: """Try to get the given key from the requests, try JSON body, form data and query arg.""" if request.is_json: oid = request.json.get(key) @@ -765,6 +765,9 @@ def _user_api_arg(key: str) -> str: oid = request.args.get(key) or request.form.get(key) if not oid: + if 'default' in kwargs: + return kwargs.get('default') + raise ValueError(f'missing {key}') return oid @@ -780,7 +783,7 @@ def _user_api_get_note(from_outbox: bool = False): def _user_api_response(**kwargs): - _redirect = _user_api_arg('redirect') + _redirect = _user_api_arg('redirect', default=None) if _redirect: return redirect(_redirect)