clientdispatch -> client, serverdispatch -> server, more error handling

This commit is contained in:
coffeepots 2018-06-05 11:33:21 +01:00
parent 179a6f6024
commit 53baf0bffc
4 changed files with 11 additions and 7 deletions

View File

@ -149,14 +149,15 @@ proc createRpcFromSig*(rpcDecl: NimNode): NimNode =
let
rpcResult = genSym(nskLet, "res") # temporary variable to hold `Response` from rpc call
clientIdent = newIdentNode("client")
procRes = ident"result" # proc return variable
jsonRpcResult = # actual return value, `rpcResult`.result
nnkDotExpr.newTree(rpcResult, newIdentNode("result"))
# perform rpc call
callBody.add(quote do:
let `rpcResult` = await client.call(`pathStr`, `jsonParamIdent`) # `rpcResult` is of type `Response`
if `rpcResult`.error: raise newException(ValueError, $`rpcResult`.result) # TODO: is raise suitable here?
let `rpcResult` = await `clientIdent`.call(`pathStr`, `jsonParamIdent`) # `rpcResult` is of type `Response`
if `rpcResult`.error: raise newException(ValueError, $`rpcResult`.result)
)
if customReturnType:

View File

@ -39,8 +39,11 @@ proc processClient(server: RpcServer, client: AsyncSocket) {.async.} =
if future.readError of RpcProcError:
let err = future.readError.RpcProcError
await client.sendError(err.code, err.msg, err.data)
elif future.readError of ValueError:
let err = future.readError[].ValueError
await client.sendError(INVALID_PARAMS, err.msg, %"")
else:
await client.sendError(SERVER_ERROR, "Error", %getCurrentExceptionMsg())
await client.sendError(SERVER_ERROR, "Error: Unknown error occurred", %"")
proc serve*(server: RpcServer) {.async.} =
server.socket.bindAddr(server.port, server.address)

View File

@ -1,3 +1,3 @@
import eth-rpc / client / clientdispatch
export clientdispatch
import eth-rpc / client / client
export client

View File

@ -1,2 +1,2 @@
import r"eth-rpc/server" / [servertypes, rpcconsts, serverdispatch]
export servertypes, rpcconsts, serverdispatch
import r"eth-rpc/server" / [servertypes, rpcconsts, server]
export servertypes, rpcconsts, server