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

Handle HttpResponseException more safely for federated groups #3969

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
13 changes: 11 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,18 @@ 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
)

def h(failure):
turt2live marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -478,7 +478,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 @@ -532,7 +532,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 @@ -587,7 +587,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 @@ -638,7 +638,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 @@ -682,7 +682,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