summary refs log tree commit diff
path: root/synapse/handlers/directory.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-11-21 15:11:48 +0000
committerMark Haines <mark.haines@matrix.org>2014-11-21 15:11:48 +0000
commitfd40a80a6885f02ebe77aa4c95a137e2e1ae9cae (patch)
treef536023eee4957fa0a1061d1ed73bb9f1b81a38c /synapse/handlers/directory.py
parentSYN-58: Allow passing explicit limit=0 to initialSync to request no messages ... (diff)
downloadsynapse-fd40a80a6885f02ebe77aa4c95a137e2e1ae9cae.tar.xz
Return 404 M_NOT_FOUND when trying to look up a room alias that doesn't exist
Diffstat (limited to '')
-rw-r--r--synapse/handlers/directory.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index af4e7d49c8..3b37e49e6f 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -17,7 +17,7 @@
 from twisted.internet import defer
 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
 
 import logging
@@ -84,22 +84,32 @@ class DirectoryHandler(BaseHandler):
                 room_id = result.room_id
                 servers = result.servers
         else:
-            result = yield self.federation.make_query(
-                destination=room_alias.domain,
-                query_type="directory",
-                args={
-                    "room_alias": room_alias.to_string(),
-                },
-                retry_on_dns_fail=False,
-            )
+            try:
+                result = yield self.federation.make_query(
+                    destination=room_alias.domain,
+                    query_type="directory",
+                    args={
+                        "room_alias": room_alias.to_string(),
+                    },
+                    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:
                 room_id = result["room_id"]
                 servers = result["servers"]
 
         if not room_id:
-            defer.returnValue({})
-            return
+            raise SynapseError(
+                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)
         servers = list(set(extra_servers) | set(servers))
@@ -129,7 +139,9 @@ class DirectoryHandler(BaseHandler):
             })
         else:
             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