Skip to content

Enhance the HTTP error and JSON-RPC error handle#342

Open
0xcary wants to merge 10 commits intosolana-foundation:mainfrom
0xcary:main
Open

Enhance the HTTP error and JSON-RPC error handle#342
0xcary wants to merge 10 commits intosolana-foundation:mainfrom
0xcary:main

Conversation

@0xcary
Copy link
Copy Markdown
Contributor

@0xcary 0xcary commented Oct 21, 2025

This pull request refactors the HTTP error handling and header management in the JSON-RPC client codebase. The main improvements include a more informative HTTPError type, proper propagation of HTTP status and body in error cases, and enhanced support for custom headers via context. Additionally, new tests have been added to verify header manipulation functionality.

Error handling improvements:

  • Refactored the HTTPError type to include StatusCode, Status, and response Body, and updated its error message formatting for better debugging. [1] [2]
  • Updated error handling in doCall, doCallWithCallbackOnHTTPResponse, and doBatchCall to return the new HTTPError with status and body, and simplified error propagation. [1] [2] [3] [4]

Header management enhancements:

  • Added context_headers.go with utilities to inject and extract HTTP headers from a context.Context, allowing per-request header customization.
  • Modified request creation to merge headers from context with client-level custom headers.

Testing improvements:

  • Added new tests in client_test.go to verify setting, modifying, removing, and retrieving headers, as well as checking that headers are correctly sent in requests.
  • Added necessary imports for HTTP testing and atomic operations.

API usage safeguards:

  • Added a panic in NewClientWithOpts if the endpoint is empty, enforcing correct usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant