mirror of
https://github.com/element-hq/synapse
synced 2024-08-20 22:30:21 +00:00
Merge pull request #3969 from turt2live/travis/fix-federated-group-requests
Handle HttpResponseException more safely for federated groups
This commit is contained in:
commit
43c3f0b02f
3 changed files with 23 additions and 8 deletions
1
changelog.d/3969.bugfix
Normal file
1
changelog.d/3969.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix HTTP error response codes for federated group requests.
|
|
@ -20,7 +20,7 @@ from six import iteritems
|
||||||
|
|
||||||
from twisted.internet import defer
|
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
|
from synapse.types import get_domain_from_id
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -37,9 +37,23 @@ def _create_rerouter(func_name):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
destination = get_domain_from_id(group_id)
|
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
|
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
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ class MatrixFederationHttpClient(object):
|
||||||
Returns:
|
Returns:
|
||||||
Deferred: resolves with the http response object on success.
|
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.
|
code >= 300.
|
||||||
|
|
||||||
Fails with ``NotRetryingDestination`` if we are not yet ready
|
Fails with ``NotRetryingDestination`` if we are not yet ready
|
||||||
|
@ -480,7 +480,7 @@ class MatrixFederationHttpClient(object):
|
||||||
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
||||||
will be the decoded JSON body.
|
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.
|
code >= 300.
|
||||||
|
|
||||||
Fails with ``NotRetryingDestination`` if we are not yet ready
|
Fails with ``NotRetryingDestination`` if we are not yet ready
|
||||||
|
@ -534,7 +534,7 @@ class MatrixFederationHttpClient(object):
|
||||||
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
||||||
will be the decoded JSON body.
|
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.
|
code >= 300.
|
||||||
|
|
||||||
Fails with ``NotRetryingDestination`` if we are not yet ready
|
Fails with ``NotRetryingDestination`` if we are not yet ready
|
||||||
|
@ -589,7 +589,7 @@ class MatrixFederationHttpClient(object):
|
||||||
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
||||||
will be the decoded JSON body.
|
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.
|
code >= 300.
|
||||||
|
|
||||||
Fails with ``NotRetryingDestination`` if we are not yet ready
|
Fails with ``NotRetryingDestination`` if we are not yet ready
|
||||||
|
@ -640,7 +640,7 @@ class MatrixFederationHttpClient(object):
|
||||||
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
Deferred: Succeeds when we get a 2xx HTTP response. The result
|
||||||
will be the decoded JSON body.
|
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.
|
code >= 300.
|
||||||
|
|
||||||
Fails with ``NotRetryingDestination`` if we are not yet ready
|
Fails with ``NotRetryingDestination`` if we are not yet ready
|
||||||
|
@ -684,7 +684,7 @@ class MatrixFederationHttpClient(object):
|
||||||
Deferred: resolves with an (int,dict) tuple of the file length and
|
Deferred: resolves with an (int,dict) tuple of the file length and
|
||||||
a dict of the response headers.
|
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
|
>= 300
|
||||||
|
|
||||||
Fails with ``NotRetryingDestination`` if we are not yet ready
|
Fails with ``NotRetryingDestination`` if we are not yet ready
|
||||||
|
|
Loading…
Reference in a new issue