From 66f236c8f1c2fb2a72c43ae20a315c44b8d15291 Mon Sep 17 00:00:00 2001 From: Amisha Singla Date: Tue, 3 Dec 2024 11:12:16 -0600 Subject: [PATCH] Use fmt error instead of error module as error module is onsolete --- utils/apiclient/client.go | 9 ++++----- utils/apiclient/request.go | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/utils/apiclient/client.go b/utils/apiclient/client.go index ccb488d76e..82501df3fc 100644 --- a/utils/apiclient/client.go +++ b/utils/apiclient/client.go @@ -8,7 +8,6 @@ import ( "net/url" "time" - "github.com/pkg/errors" "github.com/stellar/go/support/log" ) @@ -49,7 +48,7 @@ func (c *APIClient) CallAPI(reqParams RequestParams) (interface{}, error) { url := c.GetURL(reqParams.Endpoint, reqParams.QueryParams) reqBody, err := CreateRequestBody(reqParams.RequestType, url) if err != nil { - return nil, errors.Wrap(err, "http request creation failed") + return nil, fmt.Errorf("http request creation failed") } SetAuthHeaders(reqBody, c.AuthType, c.AuthHeaders) @@ -65,18 +64,18 @@ func (c *APIClient) CallAPI(reqParams RequestParams) (interface{}, error) { for retries <= c.MaxRetries { resp, err := client.Do(reqBody) if err != nil { - return nil, errors.Wrap(err, "http request failed") + return nil, fmt.Errorf("http request failed: %w", err) } defer resp.Body.Close() if resp.StatusCode == http.StatusOK { body, err := ioutil.ReadAll(resp.Body) if err != nil { - return nil, errors.Wrap(err, "failed to read response body") + return nil, fmt.Errorf("failed to read response body: %w", err) } if err := json.Unmarshal(body, &result); err != nil { - return nil, errors.Wrap(err, "failed to unmarshal JSON") + return nil, fmt.Errorf("failed to unmarshal JSON: %w", err) } return result, nil diff --git a/utils/apiclient/request.go b/utils/apiclient/request.go index 557f5b70eb..135ed1a437 100644 --- a/utils/apiclient/request.go +++ b/utils/apiclient/request.go @@ -5,14 +5,13 @@ import ( "fmt" "net/http" - "github.com/pkg/errors" "github.com/stellar/go/support/log" ) func CreateRequestBody(requestType string, url string) (*http.Request, error) { req, err := http.NewRequest(requestType, url, nil) if err != nil { - return nil, errors.Wrap(err, "http GET request creation failed") + return nil, fmt.Errorf("http GET request creation failed: %w", err) } return req, nil }