Skip to content

Commit

Permalink
refactor: add IsNilOrNotFound, remove OmitNotFound (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored May 6, 2024
1 parent 7cd0505 commit e9a81d7
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ func IsAlreadyExists(err error) bool {
return errors.As(err, &e) && strings.Contains(e.Message, "already exists") && e.Status == http.StatusConflict
}

// OmitNotFound sometimes 404 is expected, and not an error.
// For instance, when a resource is deleted in a retry loop.
func OmitNotFound(err error) error {
if IsNotFound(err) {
return nil
}

return err
// IsNilOrNotFound returns true for nil and 404 error.
// This check is quite often used for resource deletion when 404 is not an issue.
func IsNilOrNotFound(err error) bool {
return err == nil || IsNotFound(err)
}

0 comments on commit e9a81d7

Please sign in to comment.