Skip to content

Commit

Permalink
Handle both error and error pointer returns from gophercloud
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Jan 4, 2023
1 parent 4526db5 commit 8e4cf26
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/utils/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ func IsRetryable(err error) bool {
}

func IsNotFound(err error) bool {
// Gophercloud is not consistent in how it returns 404 errors. Sometimes
// it returns a pointer to the error, sometimes it returns the error
// directly.
// Some discussion here: https://github.com/gophercloud/gophercloud/issues/2279
var errDefault404 gophercloud.ErrDefault404
if errors.As(err, &errDefault404) {
return true
}

var errResourceNotFound gophercloud.ErrResourceNotFound
if errors.As(err, &errResourceNotFound) {
var pErrDefault404 *gophercloud.ErrDefault404
var errNotFound gophercloud.ErrResourceNotFound
var pErrNotFound *gophercloud.ErrResourceNotFound
if errors.As(err, &errDefault404) || errors.As(err, &pErrDefault404) || errors.As(err, &errNotFound) || errors.As(err, &pErrNotFound) {
return true
}

Expand Down

0 comments on commit 8e4cf26

Please sign in to comment.