MM-57391: improve error message (#26630)
The error reporte when moving channels and failing has been improved to show that the problem was the repeated name on the team. The error message has been unified with MM-53756 Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -4801,6 +4801,29 @@ func TestMoveChannel(t *testing.T) {
|
||||
require.Equal(t, team2.Id, ch.TeamId)
|
||||
})
|
||||
|
||||
t.Run("Should return custom error with repeated channel", func(t *testing.T) {
|
||||
channelT1 := &model.Channel{
|
||||
DisplayName: "repeated",
|
||||
Name: "repeated",
|
||||
Type: model.ChannelTypePrivate,
|
||||
TeamId: team1.Id,
|
||||
}
|
||||
channelT1, _, err := th.Client.CreateChannel(context.TODO(), channelT1)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelT2 := &model.Channel{
|
||||
DisplayName: "repeated",
|
||||
Name: "repeated",
|
||||
Type: model.ChannelTypePrivate,
|
||||
TeamId: team2.Id,
|
||||
}
|
||||
_, _, err = th.Client.CreateChannel(context.TODO(), channelT2)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.MoveChannel(context.Background(), channelT1.Id, team2.Id, false)
|
||||
require.EqualError(t, err, "A channel with that name already exists on the same team.")
|
||||
})
|
||||
|
||||
t.Run("Should move private channel", func(t *testing.T) {
|
||||
channel := th.CreatePrivateChannel()
|
||||
ch, _, err := th.SystemAdminClient.MoveChannel(context.Background(), channel.Id, team1.Id, false)
|
||||
|
||||
@@ -622,12 +622,12 @@ func (a *App) UpdateChannel(c request.CTX, channel *model.Channel) (*model.Chann
|
||||
_, err := a.Srv().Store().Channel().Update(c, channel)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
var uniqueConstraintErr *store.ErrUniqueConstraint
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &uniqueConstraintErr):
|
||||
return nil, model.NewAppError("UpdateChannel", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(err)
|
||||
case errors.As(err, &invErr):
|
||||
if invErr.Entity == "Channel" && invErr.Field == "Name" {
|
||||
return nil, model.NewAppError("UpdateChannel", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
return nil, model.NewAppError("UpdateChannel", "app.channel.update.bad_id", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
@@ -3149,10 +3149,13 @@ func (a *App) MoveChannel(c request.CTX, team *model.Team, channel *model.Channe
|
||||
channel.TeamId = team.Id
|
||||
if _, err := a.Srv().Store().Channel().Update(c, channel); err != nil {
|
||||
var appErr *model.AppError
|
||||
var uniqueConstraintErr *store.ErrUniqueConstraint
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return model.NewAppError("MoveChannel", "app.channel.update.bad_id", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
case errors.As(err, &uniqueConstraintErr):
|
||||
return model.NewAppError("MoveChannel", store.ChannelExistsError, nil, "", http.StatusBadRequest).Wrap(err)
|
||||
case errors.As(err, &appErr):
|
||||
return appErr
|
||||
default:
|
||||
|
||||
@@ -745,7 +745,7 @@ func (s SqlChannelStore) updateChannelT(transaction *sqlxTxWrapper, channel *mod
|
||||
WHERE Id=:Id`, channel)
|
||||
if err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"Name", "channels_name_teamid_key"}) {
|
||||
return nil, store.NewErrInvalidInput("Channel", "Name", channel.Name)
|
||||
return nil, store.NewErrUniqueConstraint("Name")
|
||||
}
|
||||
return nil, errors.Wrapf(err, "failed to update channel with id=%s", channel.Id)
|
||||
}
|
||||
|
||||
@@ -364,10 +364,9 @@ func testChannelStoreUpdate(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
// Make sure that the error correctly reports the wrong field to be Name
|
||||
// See https://mattermost.atlassian.net/browse/MM-53756
|
||||
var invalidInputErr *store.ErrInvalidInput
|
||||
require.ErrorAs(t, err, &invalidInputErr)
|
||||
require.Equal(t, invalidInputErr.Entity, "Channel")
|
||||
require.Equal(t, invalidInputErr.Field, "Name")
|
||||
var uniqueConstraintErr *store.ErrUniqueConstraint
|
||||
require.ErrorAs(t, err, &uniqueConstraintErr)
|
||||
require.Contains(t, uniqueConstraintErr.Columns, "Name")
|
||||
}
|
||||
|
||||
func testGetChannelUnread(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
Ссылка в новой задаче
Block a user