MM-45993: Return errors during sending websocket messages (#20760)
During attaching an object to a websocket message, we would marshal it to json and attach the string output. But if the marshalling failed, we would just log a warning and move on. This would add an empty string to the message. But the client assumes that the object is correctly attached and would fail silently if it cannot find it. So we become more strict and return the error so that it reaches the caller. https://mattermost.atlassian.net/browse/MM-45993 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
151f295d82
Коммит
14246abdef
20
app/role.go
20
app/role.go
@@ -12,7 +12,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
"github.com/mattermost/mattermost-server/v6/utils"
|
||||
)
|
||||
@@ -138,7 +137,9 @@ func (a *App) PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.sendUpdatedRoleEvent(role)
|
||||
if appErr := a.sendUpdatedRoleEvent(role); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
return role, err
|
||||
}
|
||||
@@ -225,7 +226,10 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) {
|
||||
|
||||
for _, ir := range impactedRoles {
|
||||
if ir.Name != role.Name {
|
||||
a.sendUpdatedRoleEvent(ir)
|
||||
appErr = a.sendUpdatedRoleEvent(ir)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,17 +258,15 @@ func (a *App) CheckRolesExist(roleNames []string) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) sendUpdatedRoleEvent(role *model.Role) {
|
||||
func (a *App) sendUpdatedRoleEvent(role *model.Role) *model.AppError {
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventRoleUpdated, "", "", "", nil)
|
||||
roleJSON, jsonErr := json.Marshal(role)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode role to JSON", mlog.Err(jsonErr))
|
||||
return model.NewAppError("sendUpdatedRoleEvent", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
|
||||
}
|
||||
message.Add("role", string(roleJSON))
|
||||
|
||||
a.Srv().Go(func() {
|
||||
a.Publish(message)
|
||||
})
|
||||
a.Publish(message)
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveRoles(rolesToRemove []string, roles string) string {
|
||||
|
||||
Ссылка в новой задаче
Block a user