Skip to content

Commit

Permalink
Improve error handling of non-existing rows
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Sep 24, 2023
1 parent f44523e commit 0fa517c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/service_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (s *UserService) GetUser(email string) (*models.User, error) {

err := s.db.Take(user, "email = ?", email).Error
switch {
case errors.Is(err, gorm.ErrRecordNotFound):
return nil, ErrNotFound
case err != nil:
return nil, mapDBError(err)
default:
Expand Down Expand Up @@ -79,6 +81,8 @@ func (s *UserService) GetUserKey(value string) (*models.UserKey, error) {

err := s.db.Take(key, "value = ?", value).Error
switch {
case errors.Is(err, gorm.ErrRecordNotFound):
return nil, ErrNotFound
case err != nil:
return nil, mapDBError(err)
default:
Expand Down

0 comments on commit 0fa517c

Please sign in to comment.