mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-10 08:23:11 -06:00
Neaten the control flow even more
This commit is contained in:
parent
0c8d3c55af
commit
7e6a47663c
|
|
@ -160,6 +160,13 @@ func (r joinRoomReq) joinRoomUsingServers(
|
||||||
panic(fmt.Errorf("Joining rooms that the server already in is not implemented"))
|
panic(fmt.Errorf("Joining rooms that the server already in is not implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(servers) == 0 {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 404,
|
||||||
|
JSON: jsonerror.NotFound("No candidate servers found for room"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var response util.JSONResponse
|
var response util.JSONResponse
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
response, err = r.joinRoomUsingServer(roomID, server)
|
response, err = r.joinRoomUsingServer(roomID, server)
|
||||||
|
|
@ -172,27 +179,20 @@ func (r joinRoomReq) joinRoomUsingServers(
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
// Every server we tried to join through resulted in an error.
|
||||||
// TODO: Generate the correct HTTP status code for all different
|
// We return the error from the last server.
|
||||||
// kinds of errors that could have happened.
|
|
||||||
// The possible errors include:
|
|
||||||
// 1) We can't connect to the remote servers.
|
|
||||||
// 2) None of the servers we could connect to think we are allowed
|
|
||||||
// to join the room.
|
|
||||||
// 3) The remote server returned something invalid.
|
|
||||||
// 4) We couldn't fetch the public keys needed to verify the
|
|
||||||
// signatures on the state events.
|
|
||||||
// 5) ...
|
|
||||||
return httputil.LogThenError(r.req, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should only be reached if the list of candidate servers was empty.
|
// TODO: Generate the correct HTTP status code for all different
|
||||||
// If the list was non-empty then either the loop body would have returned
|
// kinds of errors that could have happened.
|
||||||
// or err would be non-nil.
|
// The possible errors include:
|
||||||
return util.JSONResponse{
|
// 1) We can't connect to the remote servers.
|
||||||
Code: 404,
|
// 2) None of the servers we could connect to think we are allowed
|
||||||
JSON: jsonerror.NotFound("No candidate servers found for room"),
|
// to join the room.
|
||||||
}
|
// 3) The remote server returned something invalid.
|
||||||
|
// 4) We couldn't fetch the public keys needed to verify the
|
||||||
|
// signatures on the state events.
|
||||||
|
// 5) ...
|
||||||
|
return httputil.LogThenError(r.req, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// joinRoomUsingServer tries to join a remote room using a given matrix server.
|
// joinRoomUsingServer tries to join a remote room using a given matrix server.
|
||||||
|
|
@ -221,12 +221,10 @@ func (r joinRoomReq) joinRoomUsingServer(roomID string, server gomatrixserverlib
|
||||||
|
|
||||||
respSendJoin, err := r.federation.SendJoin(server, event)
|
respSendJoin, err := r.federation.SendJoin(server, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Try the next server in the list.
|
|
||||||
return util.JSONResponse{}, err
|
return util.JSONResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = respSendJoin.Check(r.keyRing, event); err != nil {
|
if err = respSendJoin.Check(r.keyRing, event); err != nil {
|
||||||
// Try the next server in the list.
|
|
||||||
return util.JSONResponse{}, err
|
return util.JSONResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue