Skip to content

Commit

Permalink
Merge pull request #7 from drand/fix/errormsg
Browse files Browse the repository at this point in the history
Do not combine nil errors and invalid http status in Get requests
  • Loading branch information
AnomalRoil authored Aug 21, 2024
2 parents 5c1e30c + ba6d7fe commit bde77ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
10 changes: 7 additions & 3 deletions client/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(ctx context.Context, l log.Logger, url string, chainHash []byte, transp
if err != nil {
pn = defaultClientExec
}
agent := fmt.Sprintf("drand-client-%s/1.0", path.Base(pn))
agent := fmt.Sprintf("go-client-%s/2.0", path.Base(pn))
c := &httpClient{
root: url,
client: createClient(transport),
Expand Down Expand Up @@ -320,8 +320,12 @@ func (h *httpClient) Get(ctx context.Context, round uint64) (drand.Result, error
req.Header.Set("User-Agent", h.Agent)

randResponse, err := h.client.Do(req)
if err != nil || randResponse.StatusCode != nhttp.StatusOK {
resC <- httpGetResponse{nil, fmt.Errorf("doing request %v: %w", req, err)}
if err != nil {
resC <- httpGetResponse{nil, fmt.Errorf("error doing GET request to %q: %w", url, err)}
return
}
if randResponse.StatusCode != nhttp.StatusOK {
resC <- httpGetResponse{nil, fmt.Errorf("got invalid status %d doing GET request to %q", randResponse.StatusCode, url)}
return
}
defer randResponse.Body.Close()
Expand Down
16 changes: 0 additions & 16 deletions internal/net/client.go

This file was deleted.

0 comments on commit bde77ce

Please sign in to comment.