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

Descriptive error message for rate limits #2592

Closed
jim4067 opened this issue May 1, 2024 · 2 comments
Closed

Descriptive error message for rate limits #2592

jim4067 opened this issue May 1, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@jim4067
Copy link

jim4067 commented May 1, 2024

Motivation

Getting this error message using the public endpoint

Error: failed to get recent blockhash: TypeError: fetch failed
    at Connection.getLatestBlockhash (/home/jimii/Documents/crew/test-web/node_modules/@solana/web3.js/src/connection.ts:4593:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async testConnection (/home/jimii/Documents/crew/test-web/src/main.ts:10:13)

Example use case

When using RPC methods like getLatestBlockhash that might fail if a user is rate limited, it'll be useful to alert the user about that failure being because or a rate-limit

Details

Having HTTP status codes in the error response/why the getLatestBlockhash method failed will be helpful in alerting the developer when an error arises from the RPC and not the code

@jim4067 jim4067 added the enhancement New feature or request label May 1, 2024
@steveluscher
Copy link
Contributor

We have this in the forthcoming version of web3.js. Take a look!

try {
  const latestBlockhash = await rpc.getLatestBlockhash().send();
} catch (e) {
  if (isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR)) {
    if (e.context.code === 429) {
      // We got rate limited!
    }
  }
}

I would love for you to build / rebuild whatever you're making using the new web3.js, and give us feedback!

https://github.com/solana-labs/solana-web3.js/releases/tag/tp3

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 May 10, 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

No branches or pull requests

2 participants