From 9bc1b24fef38426432931cd54667dbdb78b17571 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Thu, 14 Mar 2024 16:26:47 -0400 Subject: [PATCH] use errors.As --- util/helpers.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/helpers.go b/util/helpers.go index 7836f7ed0..c2d5b0aed 100644 --- a/util/helpers.go +++ b/util/helpers.go @@ -1,6 +1,8 @@ package util import ( + "errors" + "github.com/linode/linodego" ) @@ -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