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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
60cc775cf6
Коммит
85a69d6112
@@ -1471,14 +1471,15 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.
|
||||
}
|
||||
|
||||
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
||||
channel, errCh := a.Srv().Store.Channel().Get(channelId, true)
|
||||
if errCh != nil {
|
||||
if errCh.Id == "store.sql_channel.get.existing.app_error" {
|
||||
errCh.StatusCode = http.StatusNotFound
|
||||
return nil, errCh
|
||||
channel, err := a.Srv().Store.Channel().Get(channelId, true)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetChannel", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
errCh.StatusCode = http.StatusBadRequest
|
||||
return nil, errCh
|
||||
}
|
||||
return channel, nil
|
||||
}
|
||||
@@ -1772,7 +1773,7 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
sc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv().Store.Channel().Get(channelId, true)
|
||||
sc <- store.StoreResult{Data: channel, Err: err}
|
||||
sc <- store.StoreResult{Data: channel, NErr: err}
|
||||
close(sc)
|
||||
}()
|
||||
|
||||
@@ -1795,8 +1796,14 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
return cresult.Err
|
||||
}
|
||||
uresult := <-uc
|
||||
if uresult.Err != nil {
|
||||
return cresult.Err
|
||||
if uresult.NErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(uresult.NErr, &nfErr):
|
||||
return model.NewAppError("LeaveChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return model.NewAppError("LeaveChannel", "app.channel.get.find.app_error", nil, uresult.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
ccresult := <-mcc
|
||||
if ccresult.Err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -344,7 +345,7 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
chanChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv().Store.Channel().Get(args.ChannelId, true)
|
||||
chanChan <- store.StoreResult{Data: channel, Err: err}
|
||||
chanChan <- store.StoreResult{Data: channel, NErr: err}
|
||||
close(chanChan)
|
||||
}()
|
||||
|
||||
@@ -380,8 +381,14 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
user := ur.Data.(*model.User)
|
||||
|
||||
cr := <-chanChan
|
||||
if cr.Err != nil {
|
||||
return nil, nil, cr.Err
|
||||
if cr.NErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(cr.NErr, &nfErr):
|
||||
return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.channel.get.find.app_error", nil, cr.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
channel := cr.Data.(*model.Channel)
|
||||
|
||||
|
||||
15
app/group.go
15
app/group.go
@@ -4,9 +4,11 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
)
|
||||
|
||||
func (a *App) GetGroup(id string) (*model.Group, *model.AppError) {
|
||||
@@ -90,10 +92,15 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr
|
||||
|
||||
// reject the syncable creation if the group isn't already associated to the parent team
|
||||
if groupSyncable.Type == model.GroupSyncableTypeChannel {
|
||||
var channel *model.Channel
|
||||
channel, err = a.Srv().Store.Channel().Get(groupSyncable.SyncableId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
channel, nErr := a.Srv().Store.Channel().Get(groupSyncable.SyncableId, true)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("UpsertGroupSyncable", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("UpsertGroupSyncable", "app.channel.get.find.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
var team *model.Team
|
||||
|
||||
@@ -20,6 +20,7 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -101,7 +102,13 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
|
||||
channel, err := a.Srv().Store.Channel().Get(cookie.ChannelId, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
upstreamRequest.ChannelId = cookie.ChannelId
|
||||
|
||||
@@ -5,6 +5,7 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -94,7 +95,13 @@ func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string, setOnl
|
||||
func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
||||
channel, err := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("CreatePostMissingChannel", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("CreatePostMissingChannel", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return a.CreatePost(post, channel, triggerWebhooks, true)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -412,7 +413,13 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
|
||||
if len(hook.ChannelId) != 0 {
|
||||
channel, errCh := a.Srv().Store.Channel().Get(hook.ChannelId, true)
|
||||
if errCh != nil {
|
||||
return nil, errCh
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(errCh, &nfErr):
|
||||
return nil, model.NewAppError("CreateOutgoingWebhook", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("CreateOutgoingWebhook", "app.channel.get.find.app_error", nil, errCh.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN {
|
||||
@@ -633,10 +640,16 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
var err *model.AppError
|
||||
var err error
|
||||
channel, err = a.Srv().Store.Channel().Get(hook.ChannelId, true)
|
||||
if err != nil {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+err.Message, err.StatusCode)
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return model.NewAppError("HandleIncomingWebhook", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return model.NewAppError("HandleIncomingWebhook", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user