From fa1ec482a7bd35d1cb900f727edd0dcbb1d7c45c Mon Sep 17 00:00:00 2001 From: Meenal Trivedi <79007582+meenal06@users.noreply.github.com> Date: Mon, 26 Jul 2021 15:11:58 +0530 Subject: [PATCH] fix:Inviting to an unsupported room version return M_BAD_JSON instead of Incompatible_Version (#1930) * fix:Inviting to an unsupported room version return M_BAD_JSON instead of M_UNSUPPORTED_ROOM_VERSION Signed-off-by: Meenal Trivedi * fix Signed-off-by: Meenal Trivedi * fix Signed-off-by: Meenal Trivedi * feat: make requested changes Signed-off-by: Meenal Trivedi * Use error typecast from matrix-org/gomatrixserverlib#272 Co-authored-by: Neil Alexander --- federationapi/routing/invite.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 8795118e..46865965 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -40,22 +40,29 @@ func InviteV2( ) util.JSONResponse { inviteReq := gomatrixserverlib.InviteV2Request{} err := json.Unmarshal(request.Content(), &inviteReq) - switch err.(type) { + switch e := err.(type) { + case gomatrixserverlib.UnsupportedRoomVersionError: + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.UnsupportedRoomVersion( + fmt.Sprintf("Room version %q is not supported by this server.", e.Version), + ), + } case gomatrixserverlib.BadJSONError: return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.BadJSON(err.Error()), } case nil: + return processInvite( + httpReq.Context(), true, inviteReq.Event(), inviteReq.RoomVersion(), inviteReq.InviteRoomState(), roomID, eventID, cfg, rsAPI, keys, + ) default: return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request. " + err.Error()), } } - return processInvite( - httpReq.Context(), true, inviteReq.Event(), inviteReq.RoomVersion(), inviteReq.InviteRoomState(), roomID, eventID, cfg, rsAPI, keys, - ) } // InviteV1 implements /_matrix/federation/v1/invite/{roomID}/{eventID}