aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/sendevent.go
diff options
context:
space:
mode:
authordevonh <devon.dmytro@gmail.com>2023-05-17 00:33:27 +0000
committerGitHub <noreply@github.com>2023-05-17 00:33:27 +0000
commit67d68768574a234b733eb3e4061644fc098a69f6 (patch)
tree819e9a0a150b68181d91112ffc7e0d6030412b77 /clientapi/routing/sendevent.go
parent0489d16f95a3d9f1f5bc532e2060bd2482d7b156 (diff)
Move MakeJoin logic to GMSL (#3081)
Diffstat (limited to 'clientapi/routing/sendevent.go')
-rw-r--r--clientapi/routing/sendevent.go46
1 files changed, 30 insertions, 16 deletions
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index 2e3cd411..bc14642f 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -149,7 +149,10 @@ func SendEvent(
}
aliasRes := &api.GetAliasesForRoomIDResponse{}
if err = rsAPI.GetAliasesForRoomID(req.Context(), &api.GetAliasesForRoomIDRequest{RoomID: roomID}, aliasRes); err != nil {
- return spec.InternalServerError()
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
}
var found int
requestAliases := append(aliasReq.AltAliases, aliasReq.Alias)
@@ -193,7 +196,10 @@ func SendEvent(
false,
); err != nil {
util.GetLogger(req.Context()).WithError(err).Error("SendEvents failed")
- return spec.InternalServerError()
+ return util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
}
timeToSubmitEvent := time.Since(startedSubmittingEvent)
util.GetLogger(req.Context()).WithFields(logrus.Fields{
@@ -272,43 +278,51 @@ func generateSendEvent(
err := proto.SetContent(r)
if err != nil {
util.GetLogger(ctx).WithError(err).Error("proto.SetContent failed")
- resErr := spec.InternalServerError()
- return nil, &resErr
+ return nil, &util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
}
identity, err := cfg.Matrix.SigningIdentityFor(device.UserDomain())
if err != nil {
- resErr := spec.InternalServerError()
- return nil, &resErr
+ return nil, &util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
}
var queryRes api.QueryLatestEventsAndStateResponse
e, err := eventutil.QueryAndBuildEvent(ctx, &proto, cfg.Matrix, identity, evTime, rsAPI, &queryRes)
- if err == eventutil.ErrRoomNoExists {
+ switch specificErr := err.(type) {
+ case nil:
+ case eventutil.ErrRoomNoExists:
return nil, &util.JSONResponse{
Code: http.StatusNotFound,
JSON: spec.NotFound("Room does not exist"),
}
- } else if e, ok := err.(gomatrixserverlib.BadJSONError); ok {
+ case gomatrixserverlib.BadJSONError:
return nil, &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: spec.BadJSON(e.Error()),
+ JSON: spec.BadJSON(specificErr.Error()),
}
- } else if e, ok := err.(gomatrixserverlib.EventValidationError); ok {
- if e.Code == gomatrixserverlib.EventValidationTooLarge {
+ case gomatrixserverlib.EventValidationError:
+ if specificErr.Code == gomatrixserverlib.EventValidationTooLarge {
return nil, &util.JSONResponse{
Code: http.StatusRequestEntityTooLarge,
- JSON: spec.BadJSON(e.Error()),
+ JSON: spec.BadJSON(specificErr.Error()),
}
}
return nil, &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: spec.BadJSON(e.Error()),
+ JSON: spec.BadJSON(specificErr.Error()),
}
- } else if err != nil {
+ default:
util.GetLogger(ctx).WithError(err).Error("eventutil.BuildEvent failed")
- resErr := spec.InternalServerError()
- return nil, &resErr
+ return nil, &util.JSONResponse{
+ Code: http.StatusInternalServerError,
+ JSON: spec.InternalServerError{},
+ }
}
// check to see if this user can perform this operation