Skip to content

Commit

Permalink
fix: adiciona mais contexto ao erro
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomatavelli committed Sep 21, 2024
1 parent 02af607 commit cbe445b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '>=1.21'
go-version-file: ./go.mod
- run: go get
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
Expand Down
9 changes: 1 addition & 8 deletions millennium.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"net/http"
"net/url"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -244,12 +243,6 @@ func (m *Millennium) sendRequest(request *retryablehttp.Request, response interf
return fmt.Errorf("unable to send request: %w", err)
}

if !slices.Contains([]int{http.StatusOK, http.StatusNoContent, http.StatusCreated, http.StatusTemporaryRedirect, http.StatusPermanentRedirect}, res.StatusCode) {
defer res.Body.Close()

return fmt.Errorf("unable to send request: %s", res.Status)
}

return m.getResponse(res, &response)
}

Expand All @@ -265,7 +258,7 @@ func (m *Millennium) getResponse(res *http.Response, output interface{}) error {
if res.StatusCode >= 400 {
var resErr ResponseError
if err = json.Unmarshal(bodyRes, &resErr); err != nil {
return fmt.Errorf("unable to unmarshal error response: %w", err)
return fmt.Errorf("got error %d but unable to unmarshal error response: %w", res.StatusCode, err)
}

return &resErr
Expand Down

0 comments on commit cbe445b

Please sign in to comment.