Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3969 from turt2live/travis/fix-federated-group-re…
Browse files Browse the repository at this point in the history
…quests

Handle HttpResponseException more safely for federated groups
  • Loading branch information
turt2live authored Oct 23, 2018
2 parents b3f6ddd + 3e70482 commit 43c3f0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/3969.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix HTTP error response codes for federated group requests.
18 changes: 16 additions & 2 deletions synapse/handlers/groups_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from twisted.internet import defer

from synapse.api.errors import SynapseError
from synapse.api.errors import HttpResponseException, SynapseError
from synapse.types import get_domain_from_id

logger = logging.getLogger(__name__)
Expand All @@ -37,9 +37,23 @@ def f(self, group_id, *args, **kwargs):
)
else:
destination = get_domain_from_id(group_id)
return getattr(self.transport_client, func_name)(
d = getattr(self.transport_client, func_name)(
destination, group_id, *args, **kwargs
)

# Capture errors returned by the remote homeserver and
# re-throw specific errors as SynapseErrors. This is so
# when the remote end responds with things like 403 Not
# In Group, we can communicate that to the client instead
# of a 500.
def h(failure):
failure.trap(HttpResponseException)
e = failure.value
if e.code == 403:
raise e.to_synapse_error()
return failure
d.addErrback(h)
return d
return f


Expand Down
12 changes: 6 additions & 6 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _send_request(
Returns:
Deferred: resolves with the http response object on success.
Fails with ``HTTPRequestException``: if we get an HTTP response
Fails with ``HttpResponseException``: if we get an HTTP response
code >= 300.
Fails with ``NotRetryingDestination`` if we are not yet ready
Expand Down Expand Up @@ -480,7 +480,7 @@ def put_json(self, destination, path, args={}, data={},
Deferred: Succeeds when we get a 2xx HTTP response. The result
will be the decoded JSON body.
Fails with ``HTTPRequestException`` if we get an HTTP response
Fails with ``HttpResponseException`` if we get an HTTP response
code >= 300.
Fails with ``NotRetryingDestination`` if we are not yet ready
Expand Down Expand Up @@ -534,7 +534,7 @@ def post_json(self, destination, path, data={}, long_retries=False,
Deferred: Succeeds when we get a 2xx HTTP response. The result
will be the decoded JSON body.
Fails with ``HTTPRequestException`` if we get an HTTP response
Fails with ``HttpResponseException`` if we get an HTTP response
code >= 300.
Fails with ``NotRetryingDestination`` if we are not yet ready
Expand Down Expand Up @@ -589,7 +589,7 @@ def get_json(self, destination, path, args=None, retry_on_dns_fail=True,
Deferred: Succeeds when we get a 2xx HTTP response. The result
will be the decoded JSON body.
Fails with ``HTTPRequestException`` if we get an HTTP response
Fails with ``HttpResponseException`` if we get an HTTP response
code >= 300.
Fails with ``NotRetryingDestination`` if we are not yet ready
Expand Down Expand Up @@ -640,7 +640,7 @@ def delete_json(self, destination, path, long_retries=False,
Deferred: Succeeds when we get a 2xx HTTP response. The result
will be the decoded JSON body.
Fails with ``HTTPRequestException`` if we get an HTTP response
Fails with ``HttpResponseException`` if we get an HTTP response
code >= 300.
Fails with ``NotRetryingDestination`` if we are not yet ready
Expand Down Expand Up @@ -684,7 +684,7 @@ def get_file(self, destination, path, output_stream, args={},
Deferred: resolves with an (int,dict) tuple of the file length and
a dict of the response headers.
Fails with ``HTTPRequestException`` if we get an HTTP response code
Fails with ``HttpResponseException`` if we get an HTTP response code
>= 300
Fails with ``NotRetryingDestination`` if we are not yet ready
Expand Down

0 comments on commit 43c3f0b

Please sign in to comment.