mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
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
This commit is contained in:
parent
ebaaf65c54
commit
002fe05a20
16 changed files with 469 additions and 332 deletions
|
@ -98,16 +98,20 @@ func SendInvite(
|
|||
rsAPI RoomserverInternalAPI, inviteEvent gomatrixserverlib.HeaderedEvent,
|
||||
inviteRoomState []gomatrixserverlib.InviteV2StrippedState,
|
||||
sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID,
|
||||
) error {
|
||||
request := InputRoomEventsRequest{
|
||||
InputInviteEvents: []InputInviteEvent{{
|
||||
Event: inviteEvent,
|
||||
InviteRoomState: inviteRoomState,
|
||||
RoomVersion: inviteEvent.RoomVersion,
|
||||
SendAsServer: string(sendAsServer),
|
||||
TransactionID: txnID,
|
||||
}},
|
||||
) *PerformError {
|
||||
request := PerformInviteRequest{
|
||||
Event: inviteEvent,
|
||||
InviteRoomState: inviteRoomState,
|
||||
RoomVersion: inviteEvent.RoomVersion,
|
||||
SendAsServer: string(sendAsServer),
|
||||
TransactionID: txnID,
|
||||
}
|
||||
var response InputRoomEventsResponse
|
||||
return rsAPI.InputRoomEvents(ctx, &request, &response)
|
||||
var response PerformInviteResponse
|
||||
rsAPI.PerformInvite(ctx, &request, &response)
|
||||
// we need to do this because many places people will use `var err error` as the return
|
||||
// arg and a nil interface != nil pointer to a concrete interface (in this case PerformError)
|
||||
if response.Error != nil && response.Error.Msg != "" {
|
||||
return response.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue