Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not combine nil errors and invalid http status in Get requests #7

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.