From b6c92a63487d2262b798d19253977bd4fee25eae Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 13:39:13 -0400 Subject: [PATCH] fix: check for a mysql.MySQLError and error no 1062 explicitly --- account/account.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/account/account.go b/account/account.go index b838a29..bd06131 100644 --- a/account/account.go +++ b/account/account.go @@ -7,6 +7,8 @@ import ( "errors" "time" + "github.com/go-sql-driver/mysql" + "git.lumeweb.com/LumeWeb/portal/metadata" "git.lumeweb.com/LumeWeb/portal/mailer" @@ -103,6 +105,13 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver if errors.Is(result.Error, gorm.ErrDuplicatedKey) { return nil, NewAccountError(ErrKeyEmailAlreadyExists, nil) } + + if err, ok := result.Error.(*mysql.MySQLError); ok { + if err.Number == 1062 { + return nil, NewAccountError(ErrKeyEmailAlreadyExists, nil) + } + } + return nil, NewAccountError(ErrKeyAccountCreationFailed, result.Error) }