Do not wrap v1 send_join errors in [code, body]

This commit is contained in:
Kegan Dougal 2020-06-17 13:06:22 +01:00
parent e09d24e732
commit f3bf6eb9f2
2 changed files with 18 additions and 4 deletions

View file

@ -28,6 +28,10 @@ import (
"github.com/matrix-org/util"
)
type JoinError struct {
Error interface{}
}
// MakeJoin implements the /make_join API
func MakeJoin(
httpReq *http.Request,
@ -224,7 +228,9 @@ func SendJoin(
if verifyResults[0].Error != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("Signature check failed: " + verifyResults[0].Error.Error()),
JSON: JoinError{
Error: jsonerror.Forbidden("Signature check failed: " + verifyResults[0].Error.Error()),
},
}
}

View file

@ -203,12 +203,20 @@ func Setup(
res := SendJoin(
httpReq, request, cfg, rsAPI, keys, roomID, eventID,
)
// not all responses get wrapped in [code, body]
var body interface{}
body = []interface{}{
res.Code, res.JSON,
}
jerr, ok := res.JSON.(JoinError)
if ok {
body = jerr.Error
}
return util.JSONResponse{
Headers: res.Headers,
Code: res.Code,
JSON: []interface{}{
res.Code, res.JSON,
},
JSON: body,
}
},
)).Methods(http.MethodPut)