summaryrefslogtreecommitdiffstats
path: root/store/sql_user_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_user_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_user_store.go')
-rw-r--r--store/sql_user_store.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index f37a4765e..7796b7cc2 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -107,9 +107,9 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel {
}
if err := us.GetMaster().Insert(user); err != nil {
- if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique"}) {
+ if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique"}) {
result.Err = model.NewAppError("SqlUserStore.Save", "store.sql_user.save.email_exists.app_error", nil, "user_id="+user.Id+", "+err.Error(), http.StatusBadRequest)
- } else if IsUniqueConstraintError(err.Error(), []string{"Username", "users_username_key", "idx_users_username_unique"}) {
+ } else if IsUniqueConstraintError(err, []string{"Username", "users_username_key", "idx_users_username_unique"}) {
result.Err = model.NewAppError("SqlUserStore.Save", "store.sql_user.save.username_exists.app_error", nil, "user_id="+user.Id+", "+err.Error(), http.StatusBadRequest)
} else {
result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.app_error", nil, "user_id="+user.Id+", "+err.Error())
@@ -182,9 +182,9 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreCha
}
if count, err := us.GetMaster().Update(user); err != nil {
- if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique"}) {
+ if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique"}) {
result.Err = model.NewAppError("SqlUserStore.Update", "store.sql_user.update.email_taken.app_error", nil, "user_id="+user.Id+", "+err.Error(), http.StatusBadRequest)
- } else if IsUniqueConstraintError(err.Error(), []string{"Username", "users_username_key", "idx_users_username_unique"}) {
+ } else if IsUniqueConstraintError(err, []string{"Username", "users_username_key", "idx_users_username_unique"}) {
result.Err = model.NewAppError("SqlUserStore.Update", "store.sql_user.update.username_taken.app_error", nil, "user_id="+user.Id+", "+err.Error(), http.StatusBadRequest)
} else {
result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.updating.app_error", nil, "user_id="+user.Id+", "+err.Error())
@@ -321,7 +321,7 @@ func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *s
query += " WHERE Id = :UserId"
if _, err := us.GetMaster().Exec(query, map[string]interface{}{"LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId, "AuthService": service, "AuthData": authData, "Email": email}); err != nil {
- if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique", "AuthData", "users_authdata_key"}) {
+ if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique", "AuthData", "users_authdata_key"}) {
result.Err = model.NewLocAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.email_exists.app_error", map[string]interface{}{"Service": service, "Email": email}, "user_id="+userId+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.app_error", nil, "id="+userId+", "+err.Error())