Some error handling
This commit is contained in:
parent
22da1f3157
commit
60e204ae45
|
@ -15,11 +15,13 @@
|
||||||
package jsonerror
|
package jsonerror
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MatrixError represents the "standard error response" in Matrix.
|
// MatrixError represents the "standard error response" in Matrix.
|
||||||
|
@ -213,3 +215,15 @@ func NotTrusted(serverName string) *MatrixError {
|
||||||
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InternalAPIError is returned when Dendrite failed to reach an internal API.
|
||||||
|
func InternalAPIError(ctx context.Context, err error) util.JSONResponse {
|
||||||
|
logrus.WithContext(ctx).WithError(err).Error("Error reaching an internal API")
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusInternalServerError,
|
||||||
|
JSON: &MatrixError{
|
||||||
|
ErrCode: "M_INTERNAL_SERVER_ERROR",
|
||||||
|
Err: "Dendrite encountered an error reaching an internal API.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,13 +30,15 @@ func AdminEvacuateRoom(req *http.Request, device *userapi.Device, rsAPI roomserv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res := &roomserverAPI.PerformAdminEvacuateRoomResponse{}
|
res := &roomserverAPI.PerformAdminEvacuateRoomResponse{}
|
||||||
rsAPI.PerformAdminEvacuateRoom(
|
if err := rsAPI.PerformAdminEvacuateRoom(
|
||||||
req.Context(),
|
req.Context(),
|
||||||
&roomserverAPI.PerformAdminEvacuateRoomRequest{
|
&roomserverAPI.PerformAdminEvacuateRoomRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
},
|
},
|
||||||
res,
|
res,
|
||||||
)
|
); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if err := res.Error; err != nil {
|
if err := res.Error; err != nil {
|
||||||
return err.JSONResponse()
|
return err.JSONResponse()
|
||||||
}
|
}
|
||||||
|
@ -67,13 +69,15 @@ func AdminEvacuateUser(req *http.Request, device *userapi.Device, rsAPI roomserv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res := &roomserverAPI.PerformAdminEvacuateUserResponse{}
|
res := &roomserverAPI.PerformAdminEvacuateUserResponse{}
|
||||||
rsAPI.PerformAdminEvacuateUser(
|
if err := rsAPI.PerformAdminEvacuateUser(
|
||||||
req.Context(),
|
req.Context(),
|
||||||
&roomserverAPI.PerformAdminEvacuateUserRequest{
|
&roomserverAPI.PerformAdminEvacuateUserRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
},
|
},
|
||||||
res,
|
res,
|
||||||
)
|
); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if err := res.Error; err != nil {
|
if err := res.Error; err != nil {
|
||||||
return err.JSONResponse()
|
return err.JSONResponse()
|
||||||
}
|
}
|
||||||
|
|
|
@ -556,10 +556,12 @@ func createRoom(
|
||||||
if r.Visibility == "public" {
|
if r.Visibility == "public" {
|
||||||
// expose this room in the published room list
|
// expose this room in the published room list
|
||||||
var pubRes roomserverAPI.PerformPublishResponse
|
var pubRes roomserverAPI.PerformPublishResponse
|
||||||
rsAPI.PerformPublish(ctx, &roomserverAPI.PerformPublishRequest{
|
if err := rsAPI.PerformPublish(ctx, &roomserverAPI.PerformPublishRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Visibility: "public",
|
Visibility: "public",
|
||||||
}, &pubRes)
|
}, &pubRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(ctx, err)
|
||||||
|
}
|
||||||
if pubRes.Error != nil {
|
if pubRes.Error != nil {
|
||||||
// treat as non-fatal since the room is already made by this point
|
// treat as non-fatal since the room is already made by this point
|
||||||
util.GetLogger(ctx).WithError(pubRes.Error).Error("failed to visibility:public")
|
util.GetLogger(ctx).WithError(pubRes.Error).Error("failed to visibility:public")
|
||||||
|
|
|
@ -302,10 +302,12 @@ func SetVisibility(
|
||||||
}
|
}
|
||||||
|
|
||||||
var publishRes roomserverAPI.PerformPublishResponse
|
var publishRes roomserverAPI.PerformPublishResponse
|
||||||
rsAPI.PerformPublish(req.Context(), &roomserverAPI.PerformPublishRequest{
|
if err := rsAPI.PerformPublish(req.Context(), &roomserverAPI.PerformPublishRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Visibility: v.Visibility,
|
Visibility: v.Visibility,
|
||||||
}, &publishRes)
|
}, &publishRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if publishRes.Error != nil {
|
if publishRes.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(publishRes.Error).Error("PerformPublish failed")
|
util.GetLogger(req.Context()).WithError(publishRes.Error).Error("PerformPublish failed")
|
||||||
return publishRes.Error.JSONResponse()
|
return publishRes.Error.JSONResponse()
|
||||||
|
|
|
@ -81,8 +81,9 @@ func JoinRoomByIDOrAlias(
|
||||||
done := make(chan util.JSONResponse, 1)
|
done := make(chan util.JSONResponse, 1)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes)
|
if err := rsAPI.PerformJoin(req.Context(), &joinReq, &joinRes); err != nil {
|
||||||
if joinRes.Error != nil {
|
done <- jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
} else if joinRes.Error != nil {
|
||||||
done <- joinRes.Error.JSONResponse()
|
done <- joinRes.Error.JSONResponse()
|
||||||
} else {
|
} else {
|
||||||
done <- util.JSONResponse{
|
done <- util.JSONResponse{
|
||||||
|
|
|
@ -91,10 +91,12 @@ func CreateKeyBackupVersion(req *http.Request, userAPI userapi.ClientUserAPI, de
|
||||||
// Implements GET /_matrix/client/r0/room_keys/version and GET /_matrix/client/r0/room_keys/version/{version}
|
// Implements GET /_matrix/client/r0/room_keys/version and GET /_matrix/client/r0/room_keys/version/{version}
|
||||||
func KeyBackupVersion(req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version string) util.JSONResponse {
|
func KeyBackupVersion(req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version string) util.JSONResponse {
|
||||||
var queryResp userapi.QueryKeyBackupResponse
|
var queryResp userapi.QueryKeyBackupResponse
|
||||||
userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
if err := userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
||||||
UserID: device.UserID,
|
UserID: device.UserID,
|
||||||
Version: version,
|
Version: version,
|
||||||
}, &queryResp)
|
}, &queryResp); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if queryResp.Error != "" {
|
if queryResp.Error != "" {
|
||||||
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
||||||
}
|
}
|
||||||
|
@ -233,13 +235,15 @@ func GetBackupKeys(
|
||||||
req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version, roomID, sessionID string,
|
req *http.Request, userAPI userapi.ClientUserAPI, device *userapi.Device, version, roomID, sessionID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var queryResp userapi.QueryKeyBackupResponse
|
var queryResp userapi.QueryKeyBackupResponse
|
||||||
userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
if err := userAPI.QueryKeyBackup(req.Context(), &userapi.QueryKeyBackupRequest{
|
||||||
UserID: device.UserID,
|
UserID: device.UserID,
|
||||||
Version: version,
|
Version: version,
|
||||||
ReturnKeys: true,
|
ReturnKeys: true,
|
||||||
KeysForRoomID: roomID,
|
KeysForRoomID: roomID,
|
||||||
KeysForSessionID: sessionID,
|
KeysForSessionID: sessionID,
|
||||||
}, &queryResp)
|
}, &queryResp); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if queryResp.Error != "" {
|
if queryResp.Error != "" {
|
||||||
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", queryResp.Error))
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,9 @@ func UploadCrossSigningDeviceKeys(
|
||||||
sessions.addCompletedSessionStage(sessionID, authtypes.LoginTypePassword)
|
sessions.addCompletedSessionStage(sessionID, authtypes.LoginTypePassword)
|
||||||
|
|
||||||
uploadReq.UserID = device.UserID
|
uploadReq.UserID = device.UserID
|
||||||
keyserverAPI.PerformUploadDeviceKeys(req.Context(), &uploadReq.PerformUploadDeviceKeysRequest, uploadRes)
|
if err := keyserverAPI.PerformUploadDeviceKeys(req.Context(), &uploadReq.PerformUploadDeviceKeysRequest, uploadRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := uploadRes.Error; err != nil {
|
if err := uploadRes.Error; err != nil {
|
||||||
switch {
|
switch {
|
||||||
|
@ -114,7 +116,9 @@ func UploadCrossSigningDeviceSignatures(req *http.Request, keyserverAPI api.Clie
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadReq.UserID = device.UserID
|
uploadReq.UserID = device.UserID
|
||||||
keyserverAPI.PerformUploadDeviceSignatures(req.Context(), uploadReq, uploadRes)
|
if err := keyserverAPI.PerformUploadDeviceSignatures(req.Context(), uploadReq, uploadRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := uploadRes.Error; err != nil {
|
if err := uploadRes.Error; err != nil {
|
||||||
switch {
|
switch {
|
||||||
|
|
|
@ -62,7 +62,9 @@ func UploadKeys(req *http.Request, keyAPI api.ClientKeyAPI, device *userapi.Devi
|
||||||
}
|
}
|
||||||
|
|
||||||
var uploadRes api.PerformUploadKeysResponse
|
var uploadRes api.PerformUploadKeysResponse
|
||||||
keyAPI.PerformUploadKeys(req.Context(), uploadReq, &uploadRes)
|
if err := keyAPI.PerformUploadKeys(req.Context(), uploadReq, &uploadRes); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(uploadRes.Error).Error("Failed to PerformUploadKeys")
|
util.GetLogger(req.Context()).WithError(uploadRes.Error).Error("Failed to PerformUploadKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
@ -107,12 +109,14 @@ func QueryKeys(req *http.Request, keyAPI api.ClientKeyAPI, device *userapi.Devic
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
queryRes := api.QueryKeysResponse{}
|
queryRes := api.QueryKeysResponse{}
|
||||||
keyAPI.QueryKeys(req.Context(), &api.QueryKeysRequest{
|
if err := keyAPI.QueryKeys(req.Context(), &api.QueryKeysRequest{
|
||||||
UserID: device.UserID,
|
UserID: device.UserID,
|
||||||
UserToDevices: r.DeviceKeys,
|
UserToDevices: r.DeviceKeys,
|
||||||
Timeout: r.GetTimeout(),
|
Timeout: r.GetTimeout(),
|
||||||
// TODO: Token?
|
// TODO: Token?
|
||||||
}, &queryRes)
|
}, &queryRes); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
JSON: map[string]interface{}{
|
JSON: map[string]interface{}{
|
||||||
|
@ -145,10 +149,12 @@ func ClaimKeys(req *http.Request, keyAPI api.ClientKeyAPI) util.JSONResponse {
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
claimRes := api.PerformClaimKeysResponse{}
|
claimRes := api.PerformClaimKeysResponse{}
|
||||||
keyAPI.PerformClaimKeys(req.Context(), &api.PerformClaimKeysRequest{
|
if err := keyAPI.PerformClaimKeys(req.Context(), &api.PerformClaimKeysRequest{
|
||||||
OneTimeKeys: r.OneTimeKeys,
|
OneTimeKeys: r.OneTimeKeys,
|
||||||
Timeout: r.GetTimeout(),
|
Timeout: r.GetTimeout(),
|
||||||
}, &claimRes)
|
}, &claimRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if claimRes.Error != nil {
|
if claimRes.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(claimRes.Error).Error("failed to PerformClaimKeys")
|
util.GetLogger(req.Context()).WithError(claimRes.Error).Error("failed to PerformClaimKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
|
|
@ -17,6 +17,7 @@ package routing
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
@ -54,7 +55,9 @@ func PeekRoomByIDOrAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the roomserver to perform the peek.
|
// Ask the roomserver to perform the peek.
|
||||||
rsAPI.PerformPeek(req.Context(), &peekReq, &peekRes)
|
if err := rsAPI.PerformPeek(req.Context(), &peekReq, &peekRes); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if peekRes.Error != nil {
|
if peekRes.Error != nil {
|
||||||
return peekRes.Error.JSONResponse()
|
return peekRes.Error.JSONResponse()
|
||||||
}
|
}
|
||||||
|
@ -89,7 +92,9 @@ func UnpeekRoomByID(
|
||||||
}
|
}
|
||||||
unpeekRes := roomserverAPI.PerformUnpeekResponse{}
|
unpeekRes := roomserverAPI.PerformUnpeekResponse{}
|
||||||
|
|
||||||
rsAPI.PerformUnpeek(req.Context(), &unpeekReq, &unpeekRes)
|
if err := rsAPI.PerformUnpeek(req.Context(), &unpeekReq, &unpeekRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
if unpeekRes.Error != nil {
|
if unpeekRes.Error != nil {
|
||||||
return unpeekRes.Error.JSONResponse()
|
return unpeekRes.Error.JSONResponse()
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,9 @@ func UpgradeRoom(
|
||||||
}
|
}
|
||||||
upgradeResp := roomserverAPI.PerformRoomUpgradeResponse{}
|
upgradeResp := roomserverAPI.PerformRoomUpgradeResponse{}
|
||||||
|
|
||||||
rsAPI.PerformRoomUpgrade(req.Context(), &upgradeReq, &upgradeResp)
|
if err := rsAPI.PerformRoomUpgrade(req.Context(), &upgradeReq, &upgradeResp); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if upgradeResp.Error != nil {
|
if upgradeResp.Error != nil {
|
||||||
if upgradeResp.Error.Code == roomserverAPI.PerformErrorNoRoom {
|
if upgradeResp.Error.Code == roomserverAPI.PerformErrorNoRoom {
|
||||||
|
|
|
@ -30,9 +30,11 @@ func GetUserDevices(
|
||||||
userID string,
|
userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var res keyapi.QueryDeviceMessagesResponse
|
var res keyapi.QueryDeviceMessagesResponse
|
||||||
keyAPI.QueryDeviceMessages(req.Context(), &keyapi.QueryDeviceMessagesRequest{
|
if err := keyAPI.QueryDeviceMessages(req.Context(), &keyapi.QueryDeviceMessagesRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
}, &res)
|
}, &res); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
util.GetLogger(req.Context()).WithError(res.Error).Error("keyAPI.QueryDeviceMessages failed")
|
util.GetLogger(req.Context()).WithError(res.Error).Error("keyAPI.QueryDeviceMessages failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
@ -47,7 +49,9 @@ func GetUserDevices(
|
||||||
for _, dev := range res.Devices {
|
for _, dev := range res.Devices {
|
||||||
sigReq.TargetIDs[userID] = append(sigReq.TargetIDs[userID], gomatrixserverlib.KeyID(dev.DeviceID))
|
sigReq.TargetIDs[userID] = append(sigReq.TargetIDs[userID], gomatrixserverlib.KeyID(dev.DeviceID))
|
||||||
}
|
}
|
||||||
keyAPI.QuerySignatures(req.Context(), sigReq, sigRes)
|
if err := keyAPI.QuerySignatures(req.Context(), sigReq, sigRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(req.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
response := gomatrixserverlib.RespUserDevices{
|
response := gomatrixserverlib.RespUserDevices{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
|
|
@ -392,7 +392,7 @@ func SendJoin(
|
||||||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||||
if !alreadyJoined {
|
if !alreadyJoined {
|
||||||
var response api.InputRoomEventsResponse
|
var response api.InputRoomEventsResponse
|
||||||
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
if err := rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
|
@ -401,7 +401,9 @@ func SendJoin(
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, &response)
|
}, &response); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
if response.ErrMsg != "" {
|
if response.ErrMsg != "" {
|
||||||
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("SendEvents failed")
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("SendEvents failed")
|
||||||
if response.NotAllowed {
|
if response.NotAllowed {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
clienthttputil "github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/dendrite/keyserver/api"
|
"github.com/matrix-org/dendrite/keyserver/api"
|
||||||
|
@ -61,9 +61,11 @@ func QueryDeviceKeys(
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryRes api.QueryKeysResponse
|
var queryRes api.QueryKeysResponse
|
||||||
keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
|
if err := keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
|
||||||
UserToDevices: qkr.DeviceKeys,
|
UserToDevices: qkr.DeviceKeys,
|
||||||
}, &queryRes)
|
}, &queryRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
if queryRes.Error != nil {
|
if queryRes.Error != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(queryRes.Error).Error("Failed to QueryKeys")
|
util.GetLogger(httpReq.Context()).WithError(queryRes.Error).Error("Failed to QueryKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
@ -113,9 +115,11 @@ func ClaimOneTimeKeys(
|
||||||
}
|
}
|
||||||
|
|
||||||
var claimRes api.PerformClaimKeysResponse
|
var claimRes api.PerformClaimKeysResponse
|
||||||
keyAPI.PerformClaimKeys(httpReq.Context(), &api.PerformClaimKeysRequest{
|
if err := keyAPI.PerformClaimKeys(httpReq.Context(), &api.PerformClaimKeysRequest{
|
||||||
OneTimeKeys: cor.OneTimeKeys,
|
OneTimeKeys: cor.OneTimeKeys,
|
||||||
}, &claimRes)
|
}, &claimRes); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
if claimRes.Error != nil {
|
if claimRes.Error != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(claimRes.Error).Error("Failed to PerformClaimKeys")
|
util.GetLogger(httpReq.Context()).WithError(claimRes.Error).Error("Failed to PerformClaimKeys")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
@ -184,7 +188,7 @@ func NotaryKeys(
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
req = &gomatrixserverlib.PublicKeyNotaryLookupRequest{}
|
req = &gomatrixserverlib.PublicKeyNotaryLookupRequest{}
|
||||||
if reqErr := httputil.UnmarshalJSONRequest(httpReq, &req); reqErr != nil {
|
if reqErr := clienthttputil.UnmarshalJSONRequest(httpReq, &req); reqErr != nil {
|
||||||
return *reqErr
|
return *reqErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,7 @@ func SendLeave(
|
||||||
// We are responsible for notifying other servers that the user has left
|
// We are responsible for notifying other servers that the user has left
|
||||||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||||
var response api.InputRoomEventsResponse
|
var response api.InputRoomEventsResponse
|
||||||
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
if err := rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
|
@ -286,7 +286,9 @@ func SendLeave(
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, &response)
|
}, &response); err != nil {
|
||||||
|
return jsonerror.InternalAPIError(httpReq.Context(), err)
|
||||||
|
}
|
||||||
|
|
||||||
if response.ErrMsg != "" {
|
if response.ErrMsg != "" {
|
||||||
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).WithField("not_allowed", response.NotAllowed).Error("producer.SendEvents failed")
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).WithField("not_allowed", response.NotAllowed).Error("producer.SendEvents failed")
|
||||||
|
|
|
@ -458,7 +458,9 @@ func (t *txnReq) processSigningKeyUpdate(ctx context.Context, e gomatrixserverli
|
||||||
UserID: updatePayload.UserID,
|
UserID: updatePayload.UserID,
|
||||||
}
|
}
|
||||||
uploadRes := &keyapi.PerformUploadDeviceKeysResponse{}
|
uploadRes := &keyapi.PerformUploadDeviceKeysResponse{}
|
||||||
t.keyAPI.PerformUploadDeviceKeys(ctx, uploadReq, uploadRes)
|
if err := t.keyAPI.PerformUploadDeviceKeys(ctx, uploadReq, uploadRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
return uploadRes.Error
|
return uploadRes.Error
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,9 @@ func SendInputRoomEvents(
|
||||||
Asynchronous: async,
|
Asynchronous: async,
|
||||||
}
|
}
|
||||||
var response InputRoomEventsResponse
|
var response InputRoomEventsResponse
|
||||||
rsAPI.InputRoomEvents(ctx, &request, &response)
|
if err := rsAPI.InputRoomEvents(ctx, &request, &response); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return response.Err()
|
return response.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,9 @@ func (r *Inviter) PerformInvite(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
inputRes := &api.InputRoomEventsResponse{}
|
inputRes := &api.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(context.Background(), inputReq, inputRes)
|
if err = r.Inputer.InputRoomEvents(context.Background(), inputReq, inputRes); err != nil {
|
||||||
|
return nil, fmt.Errorf("r.Inputer.InputRoomEvents: %w", err)
|
||||||
|
}
|
||||||
if err = inputRes.Err(); err != nil {
|
if err = inputRes.Err(); err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Msg: fmt.Sprintf("r.InputRoomEvents: %s", err.Error()),
|
Msg: fmt.Sprintf("r.InputRoomEvents: %s", err.Error()),
|
||||||
|
|
|
@ -292,7 +292,12 @@ func (r *Joiner) performJoinRoomByID(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
inputRes := rsAPI.InputRoomEventsResponse{}
|
inputRes := rsAPI.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes)
|
if err = r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil {
|
||||||
|
return "", "", &rsAPI.PerformError{
|
||||||
|
Code: rsAPI.PerformErrorNoOperation,
|
||||||
|
Msg: fmt.Sprintf("InputRoomEvents failed: %s", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
if err = inputRes.Err(); err != nil {
|
if err = inputRes.Err(); err != nil {
|
||||||
return "", "", &rsAPI.PerformError{
|
return "", "", &rsAPI.PerformError{
|
||||||
Code: rsAPI.PerformErrorNotAllowed,
|
Code: rsAPI.PerformErrorNotAllowed,
|
||||||
|
|
|
@ -186,7 +186,9 @@ func (r *Leaver) performLeaveRoomByID(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
inputRes := api.InputRoomEventsResponse{}
|
inputRes := api.InputRoomEventsResponse{}
|
||||||
r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes)
|
if err = r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil {
|
||||||
|
return nil, fmt.Errorf("r.Inputer.InputRoomEvents: %w", err)
|
||||||
|
}
|
||||||
if err = inputRes.Err(); err != nil {
|
if err = inputRes.Err(); err != nil {
|
||||||
return nil, fmt.Errorf("r.InputRoomEvents: %w", err)
|
return nil, fmt.Errorf("r.InputRoomEvents: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,22 +287,24 @@ func publishNewRoomAndUnpublishOldRoom(
|
||||||
) {
|
) {
|
||||||
// expose this room in the published room list
|
// expose this room in the published room list
|
||||||
var pubNewRoomRes api.PerformPublishResponse
|
var pubNewRoomRes api.PerformPublishResponse
|
||||||
URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
if err := URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
||||||
RoomID: newRoomID,
|
RoomID: newRoomID,
|
||||||
Visibility: "public",
|
Visibility: "public",
|
||||||
}, &pubNewRoomRes)
|
}, &pubNewRoomRes); err != nil {
|
||||||
if pubNewRoomRes.Error != nil {
|
util.GetLogger(ctx).WithError(err).Error("failed to reach internal API")
|
||||||
|
} else if pubNewRoomRes.Error != nil {
|
||||||
// treat as non-fatal since the room is already made by this point
|
// treat as non-fatal since the room is already made by this point
|
||||||
util.GetLogger(ctx).WithError(pubNewRoomRes.Error).Error("failed to visibility:public")
|
util.GetLogger(ctx).WithError(pubNewRoomRes.Error).Error("failed to visibility:public")
|
||||||
}
|
}
|
||||||
|
|
||||||
var unpubOldRoomRes api.PerformPublishResponse
|
var unpubOldRoomRes api.PerformPublishResponse
|
||||||
// remove the old room from the published room list
|
// remove the old room from the published room list
|
||||||
URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
if err := URSAPI.PerformPublish(ctx, &api.PerformPublishRequest{
|
||||||
RoomID: oldRoomID,
|
RoomID: oldRoomID,
|
||||||
Visibility: "private",
|
Visibility: "private",
|
||||||
}, &unpubOldRoomRes)
|
}, &unpubOldRoomRes); err != nil {
|
||||||
if unpubOldRoomRes.Error != nil {
|
util.GetLogger(ctx).WithError(err).Error("failed to reach internal API")
|
||||||
|
} else if unpubOldRoomRes.Error != nil {
|
||||||
// treat as non-fatal since the room is already made by this point
|
// treat as non-fatal since the room is already made by this point
|
||||||
util.GetLogger(ctx).WithError(unpubOldRoomRes.Error).Error("failed to visibility:private")
|
util.GetLogger(ctx).WithError(unpubOldRoomRes.Error).Error("failed to visibility:private")
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,9 @@ func TestMSC2836(t *testing.T) {
|
||||||
// make everyone joined to each other's rooms
|
// make everyone joined to each other's rooms
|
||||||
nopRsAPI := &testRoomserverAPI{
|
nopRsAPI := &testRoomserverAPI{
|
||||||
userToJoinedRooms: map[string][]string{
|
userToJoinedRooms: map[string][]string{
|
||||||
alice: []string{roomID},
|
alice: {roomID},
|
||||||
bob: []string{roomID},
|
bob: {roomID},
|
||||||
charlie: []string{roomID},
|
charlie: {roomID},
|
||||||
},
|
},
|
||||||
events: map[string]*gomatrixserverlib.HeaderedEvent{
|
events: map[string]*gomatrixserverlib.HeaderedEvent{
|
||||||
eventA.EventID(): eventA,
|
eventA.EventID(): eventA,
|
||||||
|
|
|
@ -192,7 +192,9 @@ func (a *UserInternalAPI) PerformDeviceDeletion(ctx context.Context, req *api.Pe
|
||||||
deleteReq.KeyIDs = append(deleteReq.KeyIDs, gomatrixserverlib.KeyID(keyID))
|
deleteReq.KeyIDs = append(deleteReq.KeyIDs, gomatrixserverlib.KeyID(keyID))
|
||||||
}
|
}
|
||||||
deleteRes := &keyapi.PerformDeleteKeysResponse{}
|
deleteRes := &keyapi.PerformDeleteKeysResponse{}
|
||||||
a.KeyAPI.PerformDeleteKeys(ctx, deleteReq, deleteRes)
|
if err := a.KeyAPI.PerformDeleteKeys(ctx, deleteReq, deleteRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := deleteRes.Error; err != nil {
|
if err := deleteRes.Error; err != nil {
|
||||||
return fmt.Errorf("a.KeyAPI.PerformDeleteKeys: %w", err)
|
return fmt.Errorf("a.KeyAPI.PerformDeleteKeys: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -211,10 +213,12 @@ func (a *UserInternalAPI) deviceListUpdate(userID string, deviceIDs []string) er
|
||||||
}
|
}
|
||||||
|
|
||||||
var uploadRes keyapi.PerformUploadKeysResponse
|
var uploadRes keyapi.PerformUploadKeysResponse
|
||||||
a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
if err := a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
DeviceKeys: deviceKeys,
|
DeviceKeys: deviceKeys,
|
||||||
}, &uploadRes)
|
}, &uploadRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
return fmt.Errorf("failed to delete device keys: %v", uploadRes.Error)
|
return fmt.Errorf("failed to delete device keys: %v", uploadRes.Error)
|
||||||
}
|
}
|
||||||
|
@ -268,7 +272,7 @@ func (a *UserInternalAPI) PerformDeviceUpdate(ctx context.Context, req *api.Perf
|
||||||
if req.DisplayName != nil && dev.DisplayName != *req.DisplayName {
|
if req.DisplayName != nil && dev.DisplayName != *req.DisplayName {
|
||||||
// display name has changed: update the device key
|
// display name has changed: update the device key
|
||||||
var uploadRes keyapi.PerformUploadKeysResponse
|
var uploadRes keyapi.PerformUploadKeysResponse
|
||||||
a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
if err := a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
|
||||||
UserID: req.RequestingUserID,
|
UserID: req.RequestingUserID,
|
||||||
DeviceKeys: []keyapi.DeviceKeys{
|
DeviceKeys: []keyapi.DeviceKeys{
|
||||||
{
|
{
|
||||||
|
@ -279,7 +283,9 @@ func (a *UserInternalAPI) PerformDeviceUpdate(ctx context.Context, req *api.Perf
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
OnlyDisplayNameUpdates: true,
|
OnlyDisplayNameUpdates: true,
|
||||||
}, &uploadRes)
|
}, &uploadRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if uploadRes.Error != nil {
|
if uploadRes.Error != nil {
|
||||||
return fmt.Errorf("failed to update device key display name: %v", uploadRes.Error)
|
return fmt.Errorf("failed to update device key display name: %v", uploadRes.Error)
|
||||||
}
|
}
|
||||||
|
@ -479,7 +485,9 @@ func (a *UserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *a
|
||||||
UserID: fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName),
|
UserID: fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName),
|
||||||
}
|
}
|
||||||
evacuateRes := &rsapi.PerformAdminEvacuateUserResponse{}
|
evacuateRes := &rsapi.PerformAdminEvacuateUserResponse{}
|
||||||
a.RSAPI.PerformAdminEvacuateUser(ctx, evacuateReq, evacuateRes)
|
if err := a.RSAPI.PerformAdminEvacuateUser(ctx, evacuateReq, evacuateRes); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := evacuateRes.Error; err != nil {
|
if err := evacuateRes.Error; err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to evacuate user after account deactivation")
|
logrus.WithError(err).Errorf("Failed to evacuate user after account deactivation")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue