mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-13 11:03:06 +00:00
handle exceptions during jsonrpc init
There are too many exceptions to catch individually, including chronos raising CatchableError exceptions in await expansion. There are also many other errors captured inside of the new proc with CatchableError. Instead of making it more complicated and harder to read, I think sticking with excepting CatchableError inside of convertError is a sensible solution
This commit is contained in:
parent
69f90a3d67
commit
3b559a90de
@ -53,7 +53,7 @@ template convertError(body) =
|
||||
except JsonRpcError as error:
|
||||
raiseJsonRpcProviderError(error.msg)
|
||||
except CatchableError as error:
|
||||
raise newException(JsonRpcProviderError, error.msg)
|
||||
raiseJsonRpcProviderError(error.msg)
|
||||
|
||||
# Provider
|
||||
|
||||
@ -72,20 +72,21 @@ proc new*(
|
||||
var client: RpcClient
|
||||
var subscriptions: JsonRpcSubscriptions
|
||||
|
||||
proc initialize {.async.} =
|
||||
case parseUri(url).scheme
|
||||
of "ws", "wss":
|
||||
let websocket = newRpcWebSocketClient(getHeaders = jsonHeaders)
|
||||
await websocket.connect(url)
|
||||
client = websocket
|
||||
subscriptions = JsonRpcSubscriptions.new(websocket)
|
||||
else:
|
||||
let http = newRpcHttpClient(getHeaders = jsonHeaders)
|
||||
await http.connect(url)
|
||||
client = http
|
||||
subscriptions = JsonRpcSubscriptions.new(http,
|
||||
pollingInterval = pollingInterval)
|
||||
subscriptions.init()
|
||||
proc initialize {.async: (raises:[JsonRpcProviderError]).} =
|
||||
convertError:
|
||||
case parseUri(url).scheme
|
||||
of "ws", "wss":
|
||||
let websocket = newRpcWebSocketClient(getHeaders = jsonHeaders)
|
||||
await websocket.connect(url)
|
||||
client = websocket
|
||||
subscriptions = JsonRpcSubscriptions.new(websocket)
|
||||
else:
|
||||
let http = newRpcHttpClient(getHeaders = jsonHeaders)
|
||||
await http.connect(url)
|
||||
client = http
|
||||
subscriptions = JsonRpcSubscriptions.new(http,
|
||||
pollingInterval = pollingInterval)
|
||||
subscriptions.init()
|
||||
|
||||
proc awaitClient: Future[RpcClient] {.async:(raises:[JsonRpcProviderError]).} =
|
||||
convertError:
|
||||
@ -97,9 +98,8 @@ proc new*(
|
||||
await initialized
|
||||
return subscriptions
|
||||
|
||||
convertError:
|
||||
initialized = initialize()
|
||||
return JsonRpcProvider(client: awaitClient(), subscriptions: awaitSubscriptions())
|
||||
initialized = initialize()
|
||||
return JsonRpcProvider(client: awaitClient(), subscriptions: awaitSubscriptions())
|
||||
|
||||
proc callImpl(
|
||||
client: RpcClient,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user