aboutsummaryrefslogtreecommitdiff
path: root/federationapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-09-24 17:16:59 +0100
committerGitHub <noreply@github.com>2020-09-24 17:16:59 +0100
commit6fbf89a166057d657b3fb742efdfccbedbfc8436 (patch)
treeae5f68da17bb09892d52b6ef6d0aaef30ce34df7 /federationapi
parent3013ade84f65f7d255523d0beb7b721804c12ced (diff)
Return the correct error codes for v6 invite JSON violations (#1440)
* Return the correct error codes for v6 invite JSON violations * Update sytest-whitelist
Diffstat (limited to 'federationapi')
-rw-r--r--federationapi/routing/invite.go21
-rw-r--r--federationapi/routing/leave.go9
2 files changed, 26 insertions, 4 deletions
diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go
index 6ce100ef..16c0441b 100644
--- a/federationapi/routing/invite.go
+++ b/federationapi/routing/invite.go
@@ -39,7 +39,15 @@ func InviteV2(
keys gomatrixserverlib.JSONVerifier,
) util.JSONResponse {
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{
Code: http.StatusBadRequest,
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
body := request.Content()
event, err := gomatrixserverlib.NewEventFromTrustedJSON(body, false, roomVer)
- 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{
Code: http.StatusBadRequest,
- JSON: jsonerror.NotJSON("The request body could not be decoded into an invite v1 request: " + err.Error()),
+ JSON: jsonerror.NotJSON("The request body could not be decoded into an invite v1 request. " + err.Error()),
}
}
var strippedState []gomatrixserverlib.InviteV2StrippedState
diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go
index 8bb0a8a9..e16dfcc2 100644
--- a/federationapi/routing/leave.go
+++ b/federationapi/routing/leave.go
@@ -138,7 +138,14 @@ func SendLeave(
// Decode the event JSON from the request.
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{
Code: http.StatusBadRequest,
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),