diff options
Diffstat (limited to 'synapse/storage/directory.py')
-rw-r--r-- | synapse/storage/directory.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/synapse/storage/directory.py b/synapse/storage/directory.py index d6a7113b9c..2be9c41374 100644 --- a/synapse/storage/directory.py +++ b/synapse/storage/directory.py @@ -14,10 +14,15 @@ # limitations under the License. from ._base import SQLBaseStore + +from synapse.api.errors import SynapseError + from twisted.internet import defer from collections import namedtuple +import sqlite3 + RoomAliasMapping = namedtuple( "RoomAliasMapping", @@ -75,13 +80,18 @@ class DirectoryStore(SQLBaseStore): Returns: Deferred """ - yield self._simple_insert( - "room_aliases", - { - "room_alias": room_alias.to_string(), - "room_id": room_id, - }, - ) + try: + yield self._simple_insert( + "room_aliases", + { + "room_alias": room_alias.to_string(), + "room_id": room_id, + }, + ) + except sqlite3.IntegrityError: + raise SynapseError( + 409, "Room alias %s already exists" % room_alias.to_string() + ) for server in servers: # TODO(erikj): Fix this to bulk insert |