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 /federationapi | |
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 'federationapi')
-rw-r--r-- | federationapi/routing/invite.go | 6 | ||||
-rw-r--r-- | federationapi/routing/send_test.go | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 7d02bc1d..b1d84f25 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -98,15 +98,15 @@ func Invite( ) // Add the invite event to the roomserver. - if err = api.SendInvite( + if perr := api.SendInvite( httpReq.Context(), rsAPI, signedEvent.Headered(inviteReq.RoomVersion()), inviteReq.InviteRoomState(), event.Origin(), nil, - ); err != nil { + ); perr != nil { util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed") - return jsonerror.InternalServerError() + return perr.JSONResponse() } // Return the signed event to the originating server, it should then tell diff --git a/federationapi/routing/send_test.go b/federationapi/routing/send_test.go index e512f4b4..3f5d5f4e 100644 --- a/federationapi/routing/send_test.go +++ b/federationapi/routing/send_test.go @@ -97,12 +97,18 @@ func (t *testRoomserverAPI) InputRoomEvents( return nil } +func (t *testRoomserverAPI) PerformInvite( + ctx context.Context, + req *api.PerformInviteRequest, + res *api.PerformInviteResponse, +) { +} + func (t *testRoomserverAPI) PerformJoin( ctx context.Context, req *api.PerformJoinRequest, res *api.PerformJoinResponse, -) error { - return nil +) { } func (t *testRoomserverAPI) PerformLeave( |