forked from MirrorHub/synapse
Improve error responses when a remote server doesn't allow you to access its public rooms list (#6899)
This commit is contained in:
parent
5016b162fc
commit
b21000a44f
3 changed files with 33 additions and 24 deletions
1
changelog.d/6899.bugfix
Normal file
1
changelog.d/6899.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Improve error responses when accessing remote public room lists.
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
@ -105,22 +106,22 @@ class RoomListHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_public_room_list(
|
def _get_public_room_list(
|
||||||
self,
|
self,
|
||||||
limit=None,
|
limit: Optional[int] = None,
|
||||||
since_token=None,
|
since_token: Optional[str] = None,
|
||||||
search_filter=None,
|
search_filter: Optional[Dict] = None,
|
||||||
network_tuple=EMPTY_THIRD_PARTY_ID,
|
network_tuple: ThirdPartyInstanceID = EMPTY_THIRD_PARTY_ID,
|
||||||
from_federation=False,
|
from_federation: bool = False,
|
||||||
):
|
) -> Dict[str, Any]:
|
||||||
"""Generate a public room list.
|
"""Generate a public room list.
|
||||||
Args:
|
Args:
|
||||||
limit (int|None): Maximum amount of rooms to return.
|
limit: Maximum amount of rooms to return.
|
||||||
since_token (str|None)
|
since_token:
|
||||||
search_filter (dict|None): Dictionary to filter rooms by.
|
search_filter: Dictionary to filter rooms by.
|
||||||
network_tuple (ThirdPartyInstanceID): Which public list to use.
|
network_tuple: Which public list to use.
|
||||||
This can be (None, None) to indicate the main list, or a particular
|
This can be (None, None) to indicate the main list, or a particular
|
||||||
appservice and network id to use an appservice specific one.
|
appservice and network id to use an appservice specific one.
|
||||||
Setting to None returns all public rooms across all lists.
|
Setting to None returns all public rooms across all lists.
|
||||||
from_federation (bool): Whether this request originated from a
|
from_federation: Whether this request originated from a
|
||||||
federating server or a client. Used for room filtering.
|
federating server or a client. Used for room filtering.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ from synapse.api.constants import EventTypes, Membership
|
||||||
from synapse.api.errors import (
|
from synapse.api.errors import (
|
||||||
AuthError,
|
AuthError,
|
||||||
Codes,
|
Codes,
|
||||||
|
HttpResponseException,
|
||||||
InvalidClientCredentialsError,
|
InvalidClientCredentialsError,
|
||||||
SynapseError,
|
SynapseError,
|
||||||
)
|
)
|
||||||
|
@ -364,10 +365,13 @@ class PublicRoomListRestServlet(TransactionRestServlet):
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
handler = self.hs.get_room_list_handler()
|
handler = self.hs.get_room_list_handler()
|
||||||
if server:
|
if server and server != self.hs.config.server_name:
|
||||||
data = await handler.get_remote_public_room_list(
|
try:
|
||||||
server, limit=limit, since_token=since_token
|
data = await handler.get_remote_public_room_list(
|
||||||
)
|
server, limit=limit, since_token=since_token
|
||||||
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
raise e.to_synapse_error()
|
||||||
else:
|
else:
|
||||||
data = await handler.get_local_public_room_list(
|
data = await handler.get_local_public_room_list(
|
||||||
limit=limit, since_token=since_token
|
limit=limit, since_token=since_token
|
||||||
|
@ -404,15 +408,18 @@ class PublicRoomListRestServlet(TransactionRestServlet):
|
||||||
limit = None
|
limit = None
|
||||||
|
|
||||||
handler = self.hs.get_room_list_handler()
|
handler = self.hs.get_room_list_handler()
|
||||||
if server:
|
if server and server != self.hs.config.server_name:
|
||||||
data = await handler.get_remote_public_room_list(
|
try:
|
||||||
server,
|
data = await handler.get_remote_public_room_list(
|
||||||
limit=limit,
|
server,
|
||||||
since_token=since_token,
|
limit=limit,
|
||||||
search_filter=search_filter,
|
since_token=since_token,
|
||||||
include_all_networks=include_all_networks,
|
search_filter=search_filter,
|
||||||
third_party_instance_id=third_party_instance_id,
|
include_all_networks=include_all_networks,
|
||||||
)
|
third_party_instance_id=third_party_instance_id,
|
||||||
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
raise e.to_synapse_error()
|
||||||
else:
|
else:
|
||||||
data = await handler.get_local_public_room_list(
|
data = await handler.get_local_public_room_list(
|
||||||
limit=limit,
|
limit=limit,
|
||||||
|
|
Loading…
Reference in a new issue