mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Return the correct error codes for v6 invite JSON violations
This commit is contained in:
parent
3013ade84f
commit
fe1b4df76a
|
|
@ -39,7 +39,15 @@ func InviteV2(
|
||||||
keys gomatrixserverlib.JSONVerifier,
|
keys gomatrixserverlib.JSONVerifier,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
inviteReq := gomatrixserverlib.InviteV2Request{}
|
inviteReq := gomatrixserverlib.InviteV2Request{}
|
||||||
if err := json.Unmarshal(request.Content(), &inviteReq); err != nil {
|
err := json.Unmarshal(request.Content(), &inviteReq)
|
||||||
|
switch err.(type) {
|
||||||
|
case gomatrixserverlib.BadJSONError:
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.BadJSON(err.Error()),
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
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()),
|
||||||
|
|
@ -63,10 +71,17 @@ func InviteV1(
|
||||||
roomVer := gomatrixserverlib.RoomVersionV1
|
roomVer := gomatrixserverlib.RoomVersionV1
|
||||||
body := request.Content()
|
body := request.Content()
|
||||||
event, err := gomatrixserverlib.NewEventFromTrustedJSON(body, false, roomVer)
|
event, err := gomatrixserverlib.NewEventFromTrustedJSON(body, false, roomVer)
|
||||||
if err != nil {
|
switch err.(type) {
|
||||||
|
case gomatrixserverlib.BadJSONError:
|
||||||
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 v1 request: " + err.Error()),
|
JSON: jsonerror.BadJSON(err.Error()),
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.NotJSON("The request body could not be decoded into an invite v1 request. " + err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var strippedState []gomatrixserverlib.InviteV2StrippedState
|
var strippedState []gomatrixserverlib.InviteV2StrippedState
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,14 @@ func SendLeave(
|
||||||
|
|
||||||
// Decode the event JSON from the request.
|
// Decode the event JSON from the request.
|
||||||
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
|
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
|
||||||
if err != nil {
|
switch err.(type) {
|
||||||
|
case gomatrixserverlib.BadJSONError:
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.BadJSON(err.Error()),
|
||||||
|
}
|
||||||
|
case nil:
|
||||||
|
default:
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue