From: W. Trevor King Date: Mon, 22 Sep 2014 13:53:48 +0000 (-0700) Subject: nmhive.py: Return 400 errors for data-less POSTs X-Git-Tag: v0.1.0~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=68dfcb127ad432bb66f761c64260825a1ef42d23;p=nmhive.git nmhive.py: Return 400 errors for data-less POSTs Avoid: Traceback (most recent call last): File "/.../flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/.../flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/.../flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/.../flask/_compat.py", line 33, in reraise raise value File "/.../flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/.../flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/.../flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/.../flask/_compat.py", line 33, in reraise raise value File "/.../flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/.../flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/.../nmhive.py", line 59, in message_id_tags for change in changes: TypeError: 'NoneType' object is not iterable --- diff --git a/nmhive.py b/nmhive.py index 4ee6747..c500d9c 100755 --- a/nmhive.py +++ b/nmhive.py @@ -47,6 +47,8 @@ def _message_tags(message): def message_id_tags(message_id): if flask.request.method == 'POST': changes = flask.request.get_json() + if not changes: + return flask.Response(status=400) database = notmuch.Database( path=NOTMUCH_PATH, mode=notmuch.Database.MODE.READ_WRITE)