rust-web3
rust-web3 copied to clipboard
Detecting rate limiting and transport error codes
I am currently using eth_getLogs
and will occasionally get rate limited. This would be indicated by an error code 429
.
Judging by this code, this currently gets "exposed" as an error string
Err(Error::Transport(format!(
"response status code is not success: {}",
status
)
Would it be possible to expose the plain code? This would make it far easier to match on.
--edit-- In addition, Infura adds additional information into the body, which would be useful to have. i.e. the number of seconds to backoff.
I think ideally this kind of throttling should be handled by the transport layer itself. Obviously I'm also fine with exposing this as a typed error. I think Error::Transport
would could hold an enum instead of a String
?
I think ideally this kind of throttling should be handled by the transport layer itself. I think it can so long as the retry-amount is configurable? I would likely want to log that it happened though.
In general I think exposing the error code and contents in an enum would be fine.
Related: https://github.com/tomusdrw/rust-web3/pull/585
I see 0.18.0
now returns this situation as a TransportError::Code(429)
which is great.
One thing that is still missing (I think) is getting the accompanying payload message. Some servers will set the back off time or other useful information.
For example, Infura returns 429
plus a json RPC payload which contains the back off time and current rate-limiting.
Infura rate limit docs: https://docs.infura.io/infura/networks/ethereum/how-to/secure-a-project/set-rate-limits#how-do-i-know-if-im-being-rate-limited