Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Add Response#headers to SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR #3563

Closed
steveluscher opened this issue Nov 14, 2024 · 1 comment · Fixed by #3564
Closed

Add Response#headers to SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR #3563

steveluscher opened this issue Nov 14, 2024 · 1 comment · Fixed by #3564
Labels
enhancement New feature or request

Comments

@steveluscher
Copy link
Contributor

Motivation

Get an HTTP error? Sometimes the headers have useful information, like your rate limit status. Your program might like access to those headers to decide what to do next.

Thanks to Hex Luther on Stack Exchange for the suggestion.

Example use case

try {
    const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
} catch(e) {
    if (isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR)) {
        if (e.context.code === 429 /* rate limit error */) {
            const retryAfterHeaderValue = e.context.headers.get('Retry-After');
            if (retryAfterHeaderValue != null) {
                // ...
            }
        }
    }
}

Details

Whatever you do, take care that the values of Headers don't get leaked through some logging system. Consider the response headers to be sensitive information.

@steveluscher steveluscher added the enhancement New feature or request label Nov 14, 2024
@steveluscher steveluscher changed the title Add Response#headers to HTTP error Add Response#headers to SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR Nov 14, 2024
Copy link
Contributor

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant