mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Use error typecast from matrix-org/gomatrixserverlib#272
This commit is contained in:
parent
ae4416066a
commit
9ddd47fbf0
|
|
@ -38,34 +38,31 @@ func InviteV2(
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.RoomserverInternalAPI,
|
||||||
keys gomatrixserverlib.JSONVerifier,
|
keys gomatrixserverlib.JSONVerifier,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
|
||||||
inviteReq := gomatrixserverlib.InviteV2Request{}
|
inviteReq := gomatrixserverlib.InviteV2Request{}
|
||||||
err := json.Unmarshal(request.Content(), &inviteReq)
|
err := json.Unmarshal(request.Content(), &inviteReq)
|
||||||
// Check to see if the room_version is supported
|
switch e := err.(type) {
|
||||||
if _, err := roomserverVersion.SupportedRoomVersion(inviteReq.RoomVersion()); err != nil {
|
case gomatrixserverlib.UnsupportedRoomVersionError:
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnsupportedRoomVersion(
|
JSON: jsonerror.UnsupportedRoomVersion(
|
||||||
fmt.Sprintf("Room version %q is not supported by this server.", inviteReq.RoomVersion()),
|
fmt.Sprintf("Room version %q is not supported by this server.", e.Version),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
|
||||||
switch err.(type) {
|
|
||||||
case gomatrixserverlib.BadJSONError:
|
case gomatrixserverlib.BadJSONError:
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.BadJSON(err.Error()),
|
JSON: jsonerror.BadJSON(err.Error()),
|
||||||
}
|
}
|
||||||
case nil:
|
case nil:
|
||||||
|
return processInvite(
|
||||||
|
httpReq.Context(), true, inviteReq.Event(), inviteReq.RoomVersion(), inviteReq.InviteRoomState(), roomID, eventID, cfg, rsAPI, keys,
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request. " + err.Error()),
|
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}
|
// InviteV1 implements /_matrix/federation/v1/invite/{roomID}/{eventID}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue