How to handle limit errors

How do I handle infura errors? for example “Insufficient resource” or “error 429 daily limit” do not enter the catch block:

             try {
                 ws = new WebSocket(infuraAPIs); //code stop here
             } catch (error) {
                 console.log("never print; " , error)
             }

or:

             try {
                 web3 = new Web3(new Web3.providers.HttpProvider(infuraAPIsWeb))
             } catch (error) {
                 console.log("never print; " , error)
             }

Is there a way to manage? so it doesn’t make sense, what am I doing wrong?

1 Like

Hi @grok ,

have you still got this problem?

I think you need to remember that not every error will be expressed as an exception from a library call. Some “errors”, e.g. 429 rate limited, are the result of a good HTTP request and response, so no exception is raised. For these you would need to take the response and test for some of these other errors.

Full disclosure, I have not looked at the detail in the docs for (I assume) web3.js to confirm how 429 is handled.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.