mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-28 17:23:09 -06:00
Check for not allowed errors on send_leave
This commit is contained in:
parent
77d439dddf
commit
09eb86b9ec
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeLeave implements the /make_leave API
|
// MakeLeave implements the /make_leave API
|
||||||
|
|
@ -259,16 +260,27 @@ func SendLeave(
|
||||||
// Send the events to the room server.
|
// Send the events to the room server.
|
||||||
// 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
|
||||||
if err = api.SendEvents(
|
var response api.InputRoomEventsResponse
|
||||||
httpReq.Context(), rsAPI,
|
rsAPI.InputRoomEvents(httpReq.Context(), &api.InputRoomEventsRequest{
|
||||||
api.KindNew,
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
[]*gomatrixserverlib.HeaderedEvent{
|
{
|
||||||
event.Headered(verRes.RoomVersion),
|
Kind: api.KindNew,
|
||||||
|
Event: event.Headered(verRes.RoomVersion),
|
||||||
|
AuthEventIDs: event.AuthEventIDs(),
|
||||||
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
|
TransactionID: nil,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
cfg.Matrix.ServerName,
|
}, &response)
|
||||||
nil,
|
|
||||||
); err != nil {
|
if response.ErrMsg != "" {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed")
|
util.GetLogger(httpReq.Context()).WithField(logrus.ErrorKey, response.ErrMsg).Error("producer.SendEvents failed")
|
||||||
|
if response.NotAllowed {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.Forbidden(response.ErrMsg),
|
||||||
|
}
|
||||||
|
}
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue