summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2019-03-18 17:45:54 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2019-03-18 17:45:54 +0000
commit621e7f37f1a7f32ff5046060f17a1da825f9ff8b (patch)
tree4b0e1ca2864750c48270b6a1bfbb1caa89113b64 /synapse/http
parentCorrect var name (diff)
downloadsynapse-621e7f37f1a7f32ff5046060f17a1da825f9ff8b.tar.xz
Better exception handling
Diffstat (limited to 'synapse/http')
-rw-r--r--synapse/http/matrixfederationclient.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py
index b27c4c1c38..3c27686a89 100644
--- a/synapse/http/matrixfederationclient.py
+++ b/synapse/http/matrixfederationclient.py
@@ -221,30 +221,31 @@ class MatrixFederationHttpClient(object):
         """
         try:
             response = yield self._send_request(**send_request_args)
+
+            # 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,
+            )
         except HttpResponseException as e:
-            # Received a 400. Raise unless we're retrying
             if not try_trailing_slash_on_400:
+                # Received an error >= 300. Raise unless we're retrying
                 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,
-        )
+        except:
+            raise e
 
         # 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 not (response.code == 400 and body.get("errcode") == "M_UNRECOGNIZED"):
-            # Enable backoff if initially disabled
-            send_request_args["backoff_on_404"] = backoff_on_404
+        # trailing slash on Synapse <= v0.99.2.
+        # Enable backoff if initially disabled
+        send_request_args["backoff_on_404"] = backoff_on_404
 
-            # Add trailing slash
-            send_request_args["request"].path += "/"
+        # Add trailing slash
+        send_request_args["request"].path += "/"
 
-            response = yield self._send_request(**send_request_args)
-            body = yield _handle_json_response(
-                self.hs.get_reactor(), self.default_timeout, request, response,
-            )
+        response = yield self._send_request(**send_request_args)
+        body = yield _handle_json_response(
+            self.hs.get_reactor(), self.default_timeout, request, response,
+        )
 
         defer.returnValue(body)