fix: check for a mysql.MySQLError and error no 1062 explicitly
This commit is contained in:
parent
f9c834752f
commit
b6c92a6348
|
@ -7,6 +7,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
"git.lumeweb.com/LumeWeb/portal/metadata"
|
"git.lumeweb.com/LumeWeb/portal/metadata"
|
||||||
|
|
||||||
"git.lumeweb.com/LumeWeb/portal/mailer"
|
"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) {
|
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
|
||||||
return nil, NewAccountError(ErrKeyEmailAlreadyExists, nil)
|
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)
|
return nil, NewAccountError(ErrKeyAccountCreationFailed, result.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue