summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-09-06 14:00:56 -0400
committerGitHub <noreply@github.com>2017-09-06 14:00:56 -0400
commit66a4d0112587608533aa744578d2db18bd88db56 (patch)
treecf1b5410162e156d5336a5c1666e7a66a405d083 /store/sql_channel_store.go
parentf968c56890bd84295672ee0d46cc846cac2dbd47 (diff)
downloadchat-66a4d0112587608533aa744578d2db18bd88db56.tar.gz
chat-66a4d0112587608533aa744578d2db18bd88db56.tar.bz2
chat-66a4d0112587608533aa744578d2db18bd88db56.zip
Update IsUniqueConstraint to check error codes instead of message text (#7385)
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r--store/sql_channel_store.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index b18e60f81..a6261b25b 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -222,7 +222,7 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
}
if err := transaction.Insert(channel); err != nil {
- if IsUniqueConstraintError(err.Error(), []string{"Name", "channels_name_teamid_key"}) {
+ if IsUniqueConstraintError(err, []string{"Name", "channels_name_teamid_key"}) {
dupChannel := model.Channel{}
s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 {
@@ -257,7 +257,7 @@ func (s SqlChannelStore) Update(channel *model.Channel) StoreChannel {
}
if count, err := s.GetMaster().Update(channel); err != nil {
- if IsUniqueConstraintError(err.Error(), []string{"Name", "channels_name_teamid_key"}) {
+ if IsUniqueConstraintError(err, []string{"Name", "channels_name_teamid_key"}) {
dupChannel := model.Channel{}
s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name= :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 {
@@ -888,7 +888,7 @@ func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *mode
}
if err := transaction.Insert(member); err != nil {
- if IsUniqueConstraintError(err.Error(), []string{"ChannelId", "channelmembers_pkey"}) {
+ if IsUniqueConstraintError(err, []string{"ChannelId", "channelmembers_pkey"}) {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.exists.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error(), http.StatusBadRequest)
} else {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.save.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError)