diff options
author | Kegsay <kegan@matrix.org> | 2020-06-24 15:06:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-24 15:06:14 +0100 |
commit | 002fe05a203e316818c108a0dac438e5cd796a68 (patch) | |
tree | bc597b82d09007d9cff14bf2c4c6557bfe9eb125 /roomserver/inthttp/server.go | |
parent | ebaaf65c54a624e693341e32619806028a45ba2f (diff) |
Add PerformInvite and refactor how errors get handled (#1158)
* Add PerformInvite and refactor how errors get handled
- Rename `JoinError` to `PerformError`
- Remove `error` from the API function signature entirely. This forces
errors to be bundled into `PerformError` which makes it easier for callers
to detect and handle errors. On network errors, HTTP clients will make a
`PerformError`.
* Unbreak everything; thanks Go!
* Send back JSONResponse according to the PerformError
* Update federation invite code too
Diffstat (limited to 'roomserver/inthttp/server.go')
-rw-r--r-- | roomserver/inthttp/server.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go index e3b81daa..1c47e87e 100644 --- a/roomserver/inthttp/server.go +++ b/roomserver/inthttp/server.go @@ -26,6 +26,17 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) + internalAPIMux.Handle(RoomserverPerformInvitePath, + httputil.MakeInternalAPI("performInvite", func(req *http.Request) util.JSONResponse { + var request api.PerformInviteRequest + var response api.PerformInviteResponse + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + r.PerformInvite(req.Context(), &request, &response) + return util.JSONResponse{Code: http.StatusOK, JSON: &response} + }), + ) internalAPIMux.Handle(RoomserverPerformJoinPath, httputil.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse { var request api.PerformJoinRequest @@ -33,9 +44,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { if err := json.NewDecoder(req.Body).Decode(&request); err != nil { return util.MessageResponse(http.StatusBadRequest, err.Error()) } - if err := r.PerformJoin(req.Context(), &request, &response); err != nil { - response.ErrMsg = err.Error() - } + r.PerformJoin(req.Context(), &request, &response) return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) |