From 9f19b9d8dacede897f3b0bf779e93005d924ac97 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 30 Apr 2023 15:16:23 -0700 Subject: [PATCH] Swap custom implementation for errors.As() --- error.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/error.go b/error.go index 4471ecf..cb466c2 100644 --- a/error.go +++ b/error.go @@ -2,6 +2,7 @@ package jsrest import ( "encoding/json" + "errors" "fmt" "net/http" @@ -159,20 +160,10 @@ type multiUnwrap interface { } func GetHTTPError(err error) *HTTPError { - // TODO: Rewrite using errors.As - if hErr, has := err.(*HTTPError); has { //nolint:errorlint - return hErr - } + hErr := &HTTPError{} - if unwrap, ok := err.(singleUnwrap); ok { //nolint:errorlint - return GetHTTPError(unwrap.Unwrap()) - } else if unwrap, ok := err.(multiUnwrap); ok { //nolint:errorlint - for _, sub := range unwrap.Unwrap() { - hErr := GetHTTPError(sub) - if hErr != nil { - return hErr - } - } + if errors.As(err, &hErr) { + return hErr } return nil