From 6b59650753a516404d3bb038f4a55cad5d7ddcd1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 2 Apr 2015 17:45:16 +0100 Subject: Throw sensible errors on not-json when allowing empty body --- synapse/rest/client/v2_alpha/_base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'synapse/rest') 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): -- cgit 1.4.1