fix: check for a mysql.MySQLError and error no 1062 explicitly

This commit is contained in:
Derrick Hammer 2024-03-20 13:39:13 -04:00
parent f9c834752f
commit b6c92a6348
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 0 deletions

View File

@ -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)
}