Migrate Get/GetFromMaster methods from ChannelStore to return error interface (#14688)

* Advances

* Migration finished

* Rename err to normalized error

* fix imports

* Renamed key

* Renamed key

* Suggestions

* Fix i18n

* Fix tests

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Этот коммит содержится в:
Rodrigo Villablanca
2020-06-02 12:28:29 -04:00
коммит произвёл GitHub
родитель 60cc775cf6
Коммит 85a69d6112
16 изменённых файлов: 112 добавлений и 50 удалений

Просмотреть файл

@@ -725,7 +725,7 @@ func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
}
}
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
return s.get(id, false, allowFromCache)
}
@@ -743,11 +743,11 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mod
return pl, nil
}
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, error) {
return s.get(id, true, false)
}
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, *model.AppError) {
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, error) {
var db *gorp.DbMap
if master {
@@ -758,11 +758,11 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*mode
obj, err := db.Get(model.Channel{}, id)
if err != nil {
return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.find.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to find channel with id = %s", id)
}
if obj == nil {
return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.existing.app_error", nil, "id="+id, http.StatusNotFound)
return nil, store.NewErrNotFound("Channel", id)
}
ch := obj.(*model.Channel)

Просмотреть файл

@@ -10,6 +10,7 @@ import (
"strings"
sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
@@ -480,7 +481,13 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable)
insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
case model.GroupSyncableTypeChannel:
if _, err := s.Channel().Get(groupSyncable.SyncableId, false); err != nil {
return nil, err
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("CreateGroupSyncable", "store.sql_channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("CreateGroupSyncable", "store.sql_channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))