MM-45991 Wrap errors (#20785)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8e0d46e0c6
Коммит
a28a967eba
26
app/role.go
26
app/role.go
@@ -22,9 +22,9 @@ func (a *App) GetRole(id string) (*model.Role, *model.AppError) {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, "", http.StatusNotFound).Wrap(err)
|
||||
default:
|
||||
return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("GetRole", "app.role.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (a *App) GetRole(id string) (*model.Role, *model.AppError) {
|
||||
func (a *App) GetAllRoles() ([]*model.Role, *model.AppError) {
|
||||
roles, err := a.Srv().Store.Role().GetAll()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetAllRoles", "app.role.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("GetAllRoles", "app.role.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
appErr := a.Srv().mergeChannelHigherScopedPermissions(roles)
|
||||
@@ -56,9 +56,9 @@ func (s *Server) GetRoleByName(ctx context.Context, name string) (*model.Role, *
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, "", http.StatusNotFound).Wrap(nErr)
|
||||
default:
|
||||
return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("GetRoleByName", "app.role.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (a *App) GetRoleByName(ctx context.Context, name string) (*model.Role, *mod
|
||||
func (a *App) GetRolesByNames(names []string) ([]*model.Role, *model.AppError) {
|
||||
roles, nErr := a.Srv().Store.Role().GetByNames(names)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("GetRolesByNames", "app.role.get_by_names.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("GetRolesByNames", "app.role.get_by_names.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
err := a.mergeChannelHigherScopedPermissions(roles)
|
||||
@@ -105,7 +105,7 @@ func (s *Server) mergeChannelHigherScopedPermissions(roles []*model.Role) *model
|
||||
|
||||
higherScopedPermissionsMap, err := s.Store.Role().ChannelHigherScopedPermissions(higherScopeNamesToQuery)
|
||||
if err != nil {
|
||||
return model.NewAppError("mergeChannelHigherScopedPermissions", "app.role.get_by_names.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("mergeChannelHigherScopedPermissions", "app.role.get_by_names.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
for _, role := range roles {
|
||||
@@ -158,9 +158,9 @@ func (a *App) CreateRole(role *model.Role) (*model.Role, *model.AppError) {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("CreateRole", "app.role.save.invalid_role.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateRole", "app.role.save.invalid_role.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
default:
|
||||
return nil, model.NewAppError("CreateRole", "app.role.save.insert.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("CreateRole", "app.role.save.insert.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,9 +173,9 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) {
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.save.invalid_role.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.save.invalid_role.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.save.insert.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.save.insert.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) {
|
||||
roleRetrievalFunc = func() ([]*model.Role, *model.AppError) {
|
||||
roles, nErr := a.Srv().Store.Role().AllChannelSchemeRoles()
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
return roles, nil
|
||||
@@ -206,7 +206,7 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) {
|
||||
roleRetrievalFunc = func() ([]*model.Role, *model.AppError) {
|
||||
roles, nErr := a.Srv().Store.Role().ChannelRolesUnderTeamRole(savedRole.Name)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("UpdateRole", "app.role.get.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
return roles, nil
|
||||
|
||||
Ссылка в новой задаче
Block a user