nim-ethers/ethers/errors.nim
Eric af35395ace
Convert retryable RPC/HTTP errors to RpcNetworkError type in ethers
Converts specific errors to RpcNetworkError, which can be bubbled to applications at a higher level and retried on the network (eg with exponential backoff) until resolved or timed out.
2025-05-27 18:03:19 +10:00

27 lines
768 B
Nim

import ./basics
type
SolidityError* = object of EthersError
ContractError* = object of EthersError
SignerError* = object of EthersError
SubscriptionError* = object of EthersError
ProviderError* = object of EthersError
data*: ?seq[byte]
RpcNetworkError* = object of EthersError
RpcHttpErrorResponse* = object of RpcNetworkError
RequestLimitError* = object of RpcHttpErrorResponse
RequestTimeoutError* = object of RpcHttpErrorResponse
{.push raises:[].}
proc toErr*[E1: ref CatchableError, E2: EthersError](
e1: E1,
_: type E2,
msg: string = e1.msg): ref E2 =
return newException(E2, msg, e1)
proc raiseNetworkError*(
error: ref CatchableError) {.raises: [RpcNetworkError].} =
raise newException(RpcNetworkError, error.msg, error)