mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 20:29:22 -05:00
Better exception handling
This commit is contained in:
parent
ecea5af491
commit
621e7f37f1
@ -221,20 +221,21 @@ class MatrixFederationHttpClient(object):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
response = yield self._send_request(**send_request_args)
|
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
|
# Check if it's necessary to retry with a trailing slash
|
||||||
body = yield _handle_json_response(
|
body = yield _handle_json_response(
|
||||||
self.hs.get_reactor(), self.default_timeout, request, response,
|
self.hs.get_reactor(), self.default_timeout, request, response,
|
||||||
)
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
if not try_trailing_slash_on_400:
|
||||||
|
# Received an error >= 300. Raise unless we're retrying
|
||||||
|
raise e
|
||||||
|
except:
|
||||||
|
raise e
|
||||||
|
|
||||||
# Retry with a trailing slash if we received a 400 with
|
# Retry with a trailing slash if we received a 400 with
|
||||||
# 'M_UNRECOGNIZED' which some endpoints can return when omitting a
|
# 'M_UNRECOGNIZED' which some endpoints can return when omitting a
|
||||||
# trailing slash on Synapse <= v0.99.2.
|
# trailing slash on Synapse <= v0.99.2.
|
||||||
if not (response.code == 400 and body.get("errcode") == "M_UNRECOGNIZED"):
|
|
||||||
# Enable backoff if initially disabled
|
# Enable backoff if initially disabled
|
||||||
send_request_args["backoff_on_404"] = backoff_on_404
|
send_request_args["backoff_on_404"] = backoff_on_404
|
||||||
|
|
||||||
|
@ -302,9 +302,6 @@ class FederationClientTests(HomeserverTestCase):
|
|||||||
b'{"errcode":"M_UNRECOGNIZED","error":"Unrecognized request"}'
|
b'{"errcode":"M_UNRECOGNIZED","error":"Unrecognized request"}'
|
||||||
)
|
)
|
||||||
|
|
||||||
# We should get a 400 response, then try again
|
|
||||||
self.pump()
|
|
||||||
|
|
||||||
# We should get another request wiht a trailing slash
|
# We should get another request wiht a trailing slash
|
||||||
self.assertRegex(conn.value(), b"^GET /foo/bar/")
|
self.assertRegex(conn.value(), b"^GET /foo/bar/")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user