Migrate GetChannels method from ChannelStore to return error interface (#14711)
* Migrate GetChannels method from ChannelStore to return error interface * Fix testing * Changed error type: ErrInvalidInput -> ErrNotFound * Added note about error migrations * Fix en.json * Fix i18n Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9b0ae49b55
Коммит
41d9c673cf
@@ -1551,7 +1551,18 @@ func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeD
|
||||
}
|
||||
|
||||
func (a *App) GetChannelsForUser(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetChannels(teamId, userId, includeDeleted)
|
||||
list, err := a.Srv().Store.Channel().GetChannels(teamId, userId, includeDeleted)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetChannelsForUser", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (a *App) GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||
|
||||
11
app/team.go
11
app/team.go
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/png"
|
||||
@@ -988,11 +989,13 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string)
|
||||
|
||||
var channelList *model.ChannelList
|
||||
|
||||
if channelList, err = a.Srv().Store.Channel().GetChannels(team.Id, user.Id, true); err != nil {
|
||||
if err.Id == "store.sql_channel.get_channels.not_found.app_error" {
|
||||
var nErr error
|
||||
if channelList, nErr = a.Srv().Store.Channel().GetChannels(team.Id, user.Id, true); nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if errors.As(nErr, &nfErr) {
|
||||
channelList = &model.ChannelList{}
|
||||
} else {
|
||||
return err
|
||||
return model.NewAppError("LeaveTeam", "app.channel.get_channels.get.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1342,7 +1345,7 @@ func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
|
||||
}
|
||||
|
||||
if channels, err := a.Srv().Store.Channel().GetTeamChannels(team.Id); err != nil {
|
||||
if err.Id != "store.sql_channel.get_channels.not_found.app_error" {
|
||||
if err.Id != "app.channel.get_channels.not_found.app_error" {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
||||
Ссылка в новой задаче
Block a user