8000 Add more debugging data for bad http responses (backport #638) by mergify[bot] · Pull Request #703 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add more debugging data for bad http responses (backport #638) #703

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

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000 Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[jsonrpc/client]` Improve the error message for client errors stemming from
bad HTTP responses.
([cometbft/cometbft\#638](https://github.com/cometbft/cometbft/pull/638))
13 changes: 10 additions & 3 deletions rpc/jsonrpc/client/http_json_client.go
857F
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,22 @@ func (c *Client) Call(
if err != nil {
return nil, fmt.Errorf("post failed: %w", err)
}

defer httpResponse.Body.Close()

responseBytes, err := io.ReadAll(httpResponse.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
return nil, fmt.Errorf("%s. Failed to read response body: %w", getHTTPRespErrPrefix(httpResponse), err)
}

return unmarshalResponseBytes(responseBytes, id, result)
res, err := unmarshalResponseBytes(responseBytes, id, result)
if err != nil {
return nil, fmt.Errorf("%s. %w", getHTTPRespErrPrefix(httpResponse), err)
}
return res, nil
}

func getHTTPRespErrPrefix(resp *http.Response) string {
return fmt.Sprintf("error in json rpc client, with http response metadata: (Status: %s, Protocol %s)", resp.Status, resp.Proto)
}

// NewRequestBatch starts a batch of requests for this client.
Expand Down
0