fix: update to check for ErrDuplicatedKey and return a more specific but generic error if so

This commit is contained in:
Derrick Hammer 2024-03-13 18:53:45 -04:00
parent 6ff84bbc1a
commit d946e969bc
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 0 deletions

View File

@ -100,6 +100,9 @@ func (s *AccountServiceDefault) CreateAccount(email string, password string, ver
result := s.db.Create(&user)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return nil, NewAccountError(ErrKeyEmailAlreadyExists, nil)
}
return nil, NewAccountError(ErrKeyAccountCreationFailed, result.Error)
}