diff --git a/synapse/handlers/groups_local.py b/synapse/handlers/groups_local.py
index ecdb12a7bf..0e2656ccb3 100644
--- a/synapse/handlers/groups_local.py
+++ b/synapse/handlers/groups_local.py
@@ -23,39 +23,32 @@ logger = logging.getLogger(__name__)
def _create_rerouter(func_name):
- """Returns a function that looks at the group id and calls the function
+ """Returns an async function that looks at the group id and calls the function
on federation or the local group server if the group is local
"""
- def f(self, group_id, *args, **kwargs):
+ async def f(self, group_id, *args, **kwargs):
if self.is_mine_id(group_id):
- return getattr(self.groups_server_handler, func_name)(
+ return await getattr(self.groups_server_handler, func_name)(
group_id, *args, **kwargs
)
else:
destination = get_domain_from_id(group_id)
- 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 http_response_errback(failure):
- failure.trap(HttpResponseException)
- e = failure.value
+ try:
+ return await getattr(self.transport_client, func_name)(
+ destination, group_id, *args, **kwargs
+ )
+ except HttpResponseException as e:
+ # 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.
raise e.to_synapse_error()
-
- def request_failed_errback(failure):
- failure.trap(RequestSendFailed)
+ except RequestSendFailed:
raise SynapseError(502, "Failed to contact group server")
- d.addErrback(http_response_errback)
- d.addErrback(request_failed_errback)
- return d
-
return f
|