Skip to content

Commit

Permalink
Emit verbose HTTP logging for coingecko when DEBUG_HTTP is set
Browse files Browse the repository at this point in the history
  • Loading branch information
lyricnz committed Oct 14, 2021
1 parent 781b87d commit 042e218
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/api/vendors/coingecko/v3/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import (
"net/url"
"strings"

"os"

"github.com/cointop-sh/cointop/pkg/api/vendors/coingecko/format"
"github.com/cointop-sh/cointop/pkg/api/vendors/coingecko/v3/types"
log "github.com/sirupsen/logrus"
)

var baseURL = "https://api.coingecko.com/api/v3"
Expand All @@ -31,6 +34,11 @@ func NewClient(httpClient *http.Client) *Client {
// helper
// doReq HTTP client
func doReq(req *http.Request, client *http.Client) ([]byte, error) {
debugHttp := os.Getenv("DEBUG_HTTP") != ""
if debugHttp {
log.Debugf("doReq %s %s", req.Method, req.URL)
}

resp, err := client.Do(req)
if err != nil {
return nil, err
Expand All @@ -41,6 +49,10 @@ func doReq(req *http.Request, client *http.Client) ([]byte, error) {
return nil, err
}
if 200 != resp.StatusCode {
if debugHttp {
log.Warnf("doReq Got Status '%s' from %s %s", resp.Status, req.Method, req.URL)
log.Debugf("doReq Got Body: %s", body)
}
return nil, fmt.Errorf("%s", body)
}
return body, nil
Expand Down

0 comments on commit 042e218

Please sign in to comment.