summary refs log tree commit diff
path: root/synapse/http/servlet.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-03-11 16:41:03 +0000
committerMark Haines <mark.haines@matrix.org>2016-03-11 16:41:03 +0000
commite9c1cabac26cf8e28152ebdb3caf29d4457eea0e (patch)
tree792ef6135a1a1a52f39a83a8e2ff6e2e28e949c7 /synapse/http/servlet.py
parentFix SQL statement (diff)
downloadsynapse-e9c1cabac26cf8e28152ebdb3caf29d4457eea0e.tar.xz
Use parse_json_object_from_request to parse JSON out of request bodies
Diffstat (limited to 'synapse/http/servlet.py')
-rw-r--r--synapse/http/servlet.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py
index 41c519c000..1996f8b136 100644
--- a/synapse/http/servlet.py
+++ b/synapse/http/servlet.py
@@ -128,14 +128,21 @@ def parse_json_object_from_request(request):
             if it wasn't a JSON object.
     """
     try:
-        content = simplejson.loads(request.content.read())
-        if type(content) != dict:
-            message = "Content must be a JSON object."
-            raise SynapseError(400, message, errcode=Codes.BAD_JSON)
-        return content
+        content_bytes = request.content.read()
+    except:
+        raise SynapseError(400, "Error reading JSON content.")
+
+    try:
+        content = simplejson.loads(content_bytes)
     except simplejson.JSONDecodeError:
         raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
 
+    if type(content) != dict:
+        message = "Content must be a JSON object."
+        raise SynapseError(400, message, errcode=Codes.BAD_JSON)
+
+    return content
+
 
 class RestServlet(object):