From fe5050c0a5b1ef3dddde294d64ab24d8ba26e53f Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Wed, 18 Aug 2021 04:41:30 -0700 Subject: [PATCH] Add and use M_ROOM_IN_USE (#1972) Signed-off-by: nivekuil Co-authored-by: Neil Alexander --- clientapi/jsonerror/jsonerror.go | 6 ++++++ clientapi/routing/createroom.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clientapi/jsonerror/jsonerror.go b/clientapi/jsonerror/jsonerror.go index 7accde5f..caa216e6 100644 --- a/clientapi/jsonerror/jsonerror.go +++ b/clientapi/jsonerror/jsonerror.go @@ -111,6 +111,12 @@ func UserInUse(msg string) *MatrixError { return &MatrixError{"M_USER_IN_USE", msg} } +// RoomInUse is an error returned when the client tries to make a room +// that already exists +func RoomInUse(msg string) *MatrixError { + return &MatrixError{"M_ROOM_IN_USE", msg} +} + // ASExclusive is an error returned when an application service tries to // register an username that is outside of its registered namespace, or if a // user attempts to register a username or room alias within an exclusive diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index b3b996ec..8f96c3d3 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -325,7 +325,10 @@ func createRoom( return jsonerror.InternalServerError() } if aliasResp.RoomID != "" { - return util.MessageResponse(400, "Alias already exists") + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.RoomInUse("Room ID already exists."), + } } aliasEvent = &fledglingEvent{ @@ -484,7 +487,10 @@ func createRoom( } if aliasResp.AliasExists { - return util.MessageResponse(400, "Alias already exists") + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.RoomInUse("Room alias already exists."), + } } }