summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2020-09-10 14:55:25 -0400
committerGitHub <noreply@github.com>2020-09-10 14:55:25 -0400
commitb86764662b6058dc53dd7cef923b806dc28f3a53 (patch)
tree95aecaacde9a89fec3da0885c1d0d7c03f686028 /synapse
parentRemove shared rooms info from upgrade/workers doc as it's still experimental ... (diff)
downloadsynapse-b86764662b6058dc53dd7cef923b806dc28f3a53.tar.xz
Fix the exception that is raised when invalid JSON is encountered. (#8291)
Diffstat (limited to 'synapse')
-rw-r--r--synapse/http/matrixfederationclient.py5
-rw-r--r--synapse/util/__init__.py2
2 files changed, 5 insertions, 2 deletions
diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py
index 775fad3be4..5eaf3151ce 100644
--- a/synapse/http/matrixfederationclient.py
+++ b/synapse/http/matrixfederationclient.py
@@ -54,6 +54,7 @@ from synapse.logging.opentracing import (
     start_active_span,
     tags,
 )
+from synapse.util import json_decoder
 from synapse.util.async_helpers import timeout_deferred
 from synapse.util.metrics import Measure
 
@@ -164,7 +165,9 @@ async def _handle_json_response(
     try:
         check_content_type_is_json(response.headers)
 
-        d = treq.json_content(response)
+        # Use the custom JSON decoder (partially re-implements treq.json_content).
+        d = treq.text_content(response, encoding="utf-8")
+        d.addCallback(json_decoder.decode)
         d = timeout_deferred(d, timeout=timeout_sec, reactor=reactor)
 
         body = await make_deferred_yieldable(d)
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py
index 3ad4b28fc7..a13f11f8d8 100644
--- a/synapse/util/__init__.py
+++ b/synapse/util/__init__.py
@@ -28,7 +28,7 @@ logger = logging.getLogger(__name__)
 
 def _reject_invalid_json(val):
     """Do not allow Infinity, -Infinity, or NaN values in JSON."""
-    raise json.JSONDecodeError("Invalid JSON value: '%s'" % val)
+    raise ValueError("Invalid JSON value: '%s'" % val)
 
 
 # Create a custom encoder to reduce the whitespace produced by JSON encoding and