mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 12:03:50 +01:00
Return 404 M_NOT_FOUND when trying to look up a room alias that doesn't exist
This commit is contained in:
parent
5f19c55731
commit
fd40a80a68
1 changed files with 24 additions and 12 deletions
|
@ -17,7 +17,7 @@
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
|
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError, Codes, CodeMessageException
|
||||||
from synapse.api.events.room import RoomAliasesEvent
|
from synapse.api.events.room import RoomAliasesEvent
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -84,22 +84,32 @@ class DirectoryHandler(BaseHandler):
|
||||||
room_id = result.room_id
|
room_id = result.room_id
|
||||||
servers = result.servers
|
servers = result.servers
|
||||||
else:
|
else:
|
||||||
result = yield self.federation.make_query(
|
try:
|
||||||
destination=room_alias.domain,
|
result = yield self.federation.make_query(
|
||||||
query_type="directory",
|
destination=room_alias.domain,
|
||||||
args={
|
query_type="directory",
|
||||||
"room_alias": room_alias.to_string(),
|
args={
|
||||||
},
|
"room_alias": room_alias.to_string(),
|
||||||
retry_on_dns_fail=False,
|
},
|
||||||
)
|
retry_on_dns_fail=False,
|
||||||
|
)
|
||||||
|
except CodeMessageException as e:
|
||||||
|
logging.warn("Error retrieving alias")
|
||||||
|
if e.code == 404:
|
||||||
|
result = None
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
if result and "room_id" in result and "servers" in result:
|
if result and "room_id" in result and "servers" in result:
|
||||||
room_id = result["room_id"]
|
room_id = result["room_id"]
|
||||||
servers = result["servers"]
|
servers = result["servers"]
|
||||||
|
|
||||||
if not room_id:
|
if not room_id:
|
||||||
defer.returnValue({})
|
raise SynapseError(
|
||||||
return
|
404,
|
||||||
|
"Room alias %r not found" % (room_alias.to_string(),),
|
||||||
|
Codes.NOT_FOUND
|
||||||
|
)
|
||||||
|
|
||||||
extra_servers = yield self.store.get_joined_hosts_for_room(room_id)
|
extra_servers = yield self.store.get_joined_hosts_for_room(room_id)
|
||||||
servers = list(set(extra_servers) | set(servers))
|
servers = list(set(extra_servers) | set(servers))
|
||||||
|
@ -129,7 +139,9 @@ class DirectoryHandler(BaseHandler):
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
404, "Room alias \"%s\" not found" % (room_alias,)
|
404,
|
||||||
|
"Room alias %r not found" % (room_alias.to_string(),),
|
||||||
|
Codes.NOT_FOUND
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in a new issue