This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Return the proper error (M_BAD_ALIAS) when a non-existant canonical alias is provided.
Original file line number Diff line number Diff line change @@ -906,7 +906,18 @@ def persist_and_notify_client_event(
906906 directory_handler = self .hs .get_handlers ().directory_handler
907907 if room_alias_str and room_alias_str != original_alias :
908908 room_alias = RoomAlias .from_string (room_alias_str )
909- mapping = yield directory_handler .get_association (room_alias )
909+ try :
910+ mapping = yield directory_handler .get_association (room_alias )
911+ except SynapseError as e :
912+ # Turn M_NOT_FOUND errors into M_BAD_ALIAS errors.
913+ if e .errcode == Codes .NOT_FOUND :
914+ raise SynapseError (
915+ 400 ,
916+ "Room alias %s does not point to the room"
917+ % (room_alias_str ,),
918+ Codes .BAD_ALIAS ,
919+ )
920+ raise
910921
911922 if mapping ["room_id" ] != event .room_id :
912923 raise SynapseError (
@@ -932,7 +943,18 @@ def persist_and_notify_client_event(
932943 if new_alt_aliases :
933944 for alias_str in new_alt_aliases :
934945 room_alias = RoomAlias .from_string (alias_str )
935- mapping = yield directory_handler .get_association (room_alias )
946+ try :
947+ mapping = yield directory_handler .get_association (room_alias )
948+ except SynapseError as e :
949+ # Turn M_NOT_FOUND errors into M_BAD_ALIAS errors.
950+ if e .errcode == Codes .NOT_FOUND :
951+ raise SynapseError (
952+ 400 ,
953+ "Room alias %s does not point to the room"
954+ % (room_alias_str ,),
955+ Codes .BAD_ALIAS ,
956+ )
957+ raise
936958
937959 if mapping ["room_id" ] != event .room_id :
938960 raise SynapseError (
You can’t perform that action at this time.
0 commit comments