mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-08 00:23:12 +00:00
fix improper yield usage (#175)
`yield` does not work with chronos futures
This commit is contained in:
parent
a8731e91bc
commit
33360528d2
@ -29,12 +29,10 @@ proc rpcCallNode*(path: string, params: JsonNode, id: ClientId): JsonNode =
|
||||
%{"jsonrpc": %"2.0", "method": %path, "params": params, "id": %id}
|
||||
|
||||
method call*(client: RpcClient, name: string,
|
||||
params: JsonNode): Future[Response] {.
|
||||
base, async, gcsafe, raises: [Defect].} =
|
||||
params: JsonNode): Future[Response] {.base, async.} =
|
||||
discard
|
||||
|
||||
method close*(client: RpcClient): Future[void] {.
|
||||
base, async, gcsafe, raises: [Defect].} =
|
||||
method close*(client: RpcClient): Future[void] {.base, async.} =
|
||||
discard
|
||||
|
||||
template `or`(a: JsonNode, b: typed): JsonNode =
|
||||
|
||||
@ -39,21 +39,25 @@ proc processClientRpc(rpcServer: RpcHttpServer): HttpProcessCallback =
|
||||
if not res.isNil:
|
||||
return res
|
||||
|
||||
let body = await request.getBody()
|
||||
|
||||
let headers = HttpTable.init([("Content-Type",
|
||||
let
|
||||
body = await request.getBody()
|
||||
headers = HttpTable.init([("Content-Type",
|
||||
"application/json; charset=utf-8")])
|
||||
|
||||
let future = rpcServer.route(string.fromBytes(body))
|
||||
yield future
|
||||
if future.failed:
|
||||
data =
|
||||
try:
|
||||
await rpcServer.route(string.fromBytes(body))
|
||||
except CancelledError as exc:
|
||||
raise exc
|
||||
except CatchableError as exc:
|
||||
debug "Internal error while processing JSON-RPC call"
|
||||
return await request.respond(Http503,
|
||||
"Internal error while processing JSON-RPC call",
|
||||
return await request.respond(
|
||||
Http503,
|
||||
"Internal error while processing JSON-RPC call: " & exc.msg,
|
||||
headers)
|
||||
else:
|
||||
var data = future.read()
|
||||
let res = await request.respond(Http200, data, headers)
|
||||
|
||||
res = await request.respond(Http200, data, headers)
|
||||
|
||||
trace "JSON-RPC result has been sent"
|
||||
return res
|
||||
else:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user