From e9a81d7a129efaf1609836af30a3d41e39ae2007 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Mon, 6 May 2024 12:04:44 +0200 Subject: [PATCH] refactor: add IsNilOrNotFound, remove OmitNotFound (#60) --- error.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/error.go b/error.go index f29076a..a201719 100644 --- a/error.go +++ b/error.go @@ -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) }