Skip to content

Commit

Permalink
use errors.As
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Mar 14, 2024
1 parent 97e7fe0 commit 9bc1b24
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions util/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package util

import (
"errors"

"github.com/linode/linodego"
)

Expand All @@ -11,9 +13,12 @@ func Pointer[T any](t T) *T {

// IgnoreLinodeAPIError returns the error except matches to status code
func IgnoreLinodeAPIError(err error, code int) error {
apiErr := linodego.Error{Code: code}
if apiErr.Is(err) {
err = nil
// not to be confused with linodego.APIError
var apiError *linodego.Error
if errors.As(err, &apiError) {
if apiError.StatusCode() == code {
return nil
}
}

return err
Expand Down

0 comments on commit 9bc1b24

Please sign in to comment.