summary refs log tree commit diff
path: root/synapse/http/matrixfederationclient.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2019-03-13 21:08:10 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2019-03-13 21:08:10 +0000
commitb2df0e8e2cb72a2147e6d962a0e8c5ce35233ed4 (patch)
treed25bc69c3963949c74d4e5d522ae3d1c684f4d0c /synapse/http/matrixfederationclient.py
parentis this what purgatory feels like (diff)
downloadsynapse-b2df0e8e2cb72a2147e6d962a0e8c5ce35233ed4.tar.xz
receiving a 400 caused an exception. handle it
Diffstat (limited to '')
-rw-r--r--synapse/http/matrixfederationclient.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py
index 59e758fefb..6b41639741 100644
--- a/synapse/http/matrixfederationclient.py
+++ b/synapse/http/matrixfederationclient.py
@@ -212,27 +212,34 @@ class MatrixFederationHttpClient(object):
             send_request_args (Dict): A dictionary of arguments to pass to
                 `_send_request()`.
 
+        Raises:
+            HttpResponseException: If we get an HTTP response code >= 300
+                (except 429).
+
         Returns:
             Deferred[Dict]: Parsed JSON response body.
         """
-        response = yield self._send_request(**send_request_args)
+        try:
+            response = yield self._send_request(**send_request_args)
+        except HttpResponseException as e:
+            # Received a 400. Raise unless we're retrying
+            if not try_trailing_slash_on_400:
+                raise e
 
         # Check if it's necessary to retry with a trailing slash
         body = yield _handle_json_response(
             self.hs.get_reactor(), self.default_timeout, request, response,
         )
 
-        if not try_trailing_slash_on_400:
-            defer.returnValue(body)
-
         # Retry with a trailing slash if we received a 400 with
         # 'M_UNRECOGNIZED' which some endpoints can return when omitting a
         # trailing slash on Synapse <=v0.99.2.
-        if (response.code == 400 and body.get("errcode") == "M_UNRECOGNIZED"):
+        if not (response.code == 400 and body.get("errcode") == "M_UNRECOGNIZED"):
             # Enable backoff if initially disabled
             send_request_args["backoff_on_404"] = backoff_on_404
 
             send_request_args["path"] += "/"
+
             response = yield self._send_request(**send_request_args)
 
             body = yield _handle_json_response(