summary refs log tree commit diff
path: root/synapse/rest/client
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-04-02 17:45:16 +0100
committerDavid Baker <dave@matrix.org>2015-04-02 17:45:16 +0100
commit6b59650753a516404d3bb038f4a55cad5d7ddcd1 (patch)
tree79dea0b5d61dd90c8db02a73fb744ff59ee713f7 /synapse/rest/client
parentpep8 (diff)
downloadsynapse-6b59650753a516404d3bb038f4a55cad5d7ddcd1.tar.xz
Throw sensible errors on not-json when allowing empty body
Diffstat (limited to 'synapse/rest/client')
-rw-r--r--synapse/rest/client/v2_alpha/_base.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/synapse/rest/client/v2_alpha/_base.py b/synapse/rest/client/v2_alpha/_base.py
index 8adcc9dd95..4540e8dcf7 100644
--- a/synapse/rest/client/v2_alpha/_base.py
+++ b/synapse/rest/client/v2_alpha/_base.py
@@ -44,7 +44,10 @@ def parse_request_allow_empty(request):
     content = request.content.read()
     if content is None or content == '':
         return None
-    return simplejson.loads(content)
+    try:
+        return simplejson.loads(content)
+    except simplejson.JSONDecodeError:
+        raise SynapseError(400, "Content not JSON.")
 
 
 def parse_json_dict_from_request(request):