SqlTermsOfService migrates to plain errors (#14675)
* Advances migragint TermsOfService * Advances... * Replaced message key * Replaced message key * Replaced message key * Replaced message key * Refactor name of errors * Fix mixed type of error * Fix-imports * i18n-extract * Rollback changes * Rollback changes * Rollback changes Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
85a69d6112
Коммит
52cf817c8e
@@ -5,11 +5,12 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SqlTermsOfServiceStore struct {
|
||||
@@ -33,9 +34,9 @@ func newSqlTermsOfServiceStore(sqlStore SqlStore, metrics einterfaces.MetricsInt
|
||||
func (s SqlTermsOfServiceStore) createIndexesIfNotExists() {
|
||||
}
|
||||
|
||||
func (s SqlTermsOfServiceStore) Save(termsOfService *model.TermsOfService) (*model.TermsOfService, *model.AppError) {
|
||||
func (s SqlTermsOfServiceStore) Save(termsOfService *model.TermsOfService) (*model.TermsOfService, error) {
|
||||
if len(termsOfService.Id) > 0 {
|
||||
return nil, model.NewAppError("SqlTermsOfServiceStore.Save", "store.sql_terms_of_service_store.save.existing.app_error", nil, "id="+termsOfService.Id, http.StatusBadRequest)
|
||||
return nil, store.NewErrInvalidInput("TermsOfService", "Id", termsOfService.Id)
|
||||
}
|
||||
|
||||
termsOfService.PreSave()
|
||||
@@ -45,33 +46,33 @@ func (s SqlTermsOfServiceStore) Save(termsOfService *model.TermsOfService) (*mod
|
||||
}
|
||||
|
||||
if err := s.GetMaster().Insert(termsOfService); err != nil {
|
||||
return nil, model.NewAppError("SqlTermsOfServiceStore.Save", "store.sql_terms_of_service.save.app_error", nil, "terms_of_service_id="+termsOfService.Id+",err="+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "could not save a new TermsOfService")
|
||||
}
|
||||
|
||||
return termsOfService, nil
|
||||
}
|
||||
|
||||
func (s SqlTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.TermsOfService, *model.AppError) {
|
||||
func (s SqlTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.TermsOfService, error) {
|
||||
var termsOfService *model.TermsOfService
|
||||
|
||||
err := s.GetReplica().SelectOne(&termsOfService, "SELECT * FROM TermsOfService ORDER BY CreateAt DESC LIMIT 1")
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlTermsOfServiceStore.GetLatest", "store.sql_terms_of_service_store.get.no_rows.app_error", nil, "err="+err.Error(), http.StatusNotFound)
|
||||
return nil, store.NewErrNotFound("TermsOfService", "CreateAt=latest")
|
||||
}
|
||||
return nil, model.NewAppError("SqlTermsOfServiceStore.GetLatest", "store.sql_terms_of_service_store.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrap(err, "could not find latest TermsOfService")
|
||||
}
|
||||
|
||||
return termsOfService, nil
|
||||
}
|
||||
|
||||
func (s SqlTermsOfServiceStore) Get(id string, allowFromCache bool) (*model.TermsOfService, *model.AppError) {
|
||||
func (s SqlTermsOfServiceStore) Get(id string, allowFromCache bool) (*model.TermsOfService, error) {
|
||||
obj, err := s.GetReplica().Get(model.TermsOfService{}, id)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlTermsOfServiceStore.Get", "store.sql_terms_of_service_store.get.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "could not find TermsOfService with id=%s", id)
|
||||
}
|
||||
if obj == nil {
|
||||
return nil, model.NewAppError("SqlTermsOfServiceStore.GetLatest", "store.sql_terms_of_service_store.get.no_rows.app_error", nil, "", http.StatusNotFound)
|
||||
return nil, store.NewErrNotFound("TermsOfService", id)
|
||||
}
|
||||
return obj.(*model.TermsOfService), nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user