Skip to content

Commit

Permalink
Use fmt error instead of error module as error module is onsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
amishas157 committed Dec 3, 2024
1 parent f458853 commit 66f236c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions utils/apiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/url"
"time"

"github.com/pkg/errors"
"github.com/stellar/go/support/log"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions utils/apiclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 66f236c

Please sign in to comment.