From d946e969bc9b43d02d1f51ef7a866e60692a0f43 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 13 Mar 2024 18:53:45 -0400 Subject: [PATCH] fix: update to check for ErrDuplicatedKey and return a more specific but generic error if so --- account/account.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account/account.go b/account/account.go index e5356f4..72787c0 100644 --- a/account/account.go +++ b/account/account.go @@ -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) }