Skip to content

Commit

Permalink
log json-rpc error message, remove redundant EH (#234)
Browse files Browse the repository at this point in the history
`route` does not raise any more..
  • Loading branch information
arnetheduck authored Dec 27, 2024
1 parent 2743721 commit 08a751b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion json_rpc/servers/httpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ proc serveHTTP*(rpcServer: RpcHttpHandler, request: HttpRequestRef):
except CancelledError as exc:
raise exc
except CatchableError as exc:
debug "Internal error while processing JSON-RPC call"
debug "Internal error while processing JSON-RPC call", msg=exc.msg
defaultResponse(exc)

proc processClientRpc(rpcServer: RpcHttpServer): HttpProcessCallback2 =
Expand Down
9 changes: 6 additions & 3 deletions json_rpc/servers/socketserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ proc processClient(server: StreamServer, transport: StreamTransport) {.async: (r
let res = await rpc.route(req)
discard await transport.write(res & "\r\n")
except TransportError as ex:
error "Transport closed during processing client", msg=ex.msg
except CatchableError as ex:
error "Error occured during processing client", msg=ex.msg
error "Transport closed during processing client",
address = transport.remoteAddress(),
msg=ex.msg
except CancelledError:
error "JSON-RPC request processing cancelled",
address = transport.remoteAddress()

# Utility functions for setting up servers using stream transport addresses

Expand Down
22 changes: 9 additions & 13 deletions json_rpc/servers/websocketserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ proc serveHTTP*(rpc: RpcWebSocketHandler, request: HttpRequest)
let server = rpc.wsserver
let ws = await server.handleRequest(request)
if ws.readyState != ReadyState.Open:
error "Failed to open websocket connection"
error "Failed to open websocket connection",
address = $request.uri
return

trace "Websocket handshake completed"
while ws.readyState != ReadyState.Closed:
let req = await ws.recvMsg()
debug "Received JSON-RPC request", len = req.len
debug "Received JSON-RPC request",
address = $request.uri,
len = req.len

if ws.readyState == ReadyState.Closed:
# if session already terminated by peer,
Expand All @@ -64,27 +67,20 @@ proc serveHTTP*(rpc: RpcWebSocketHandler, request: HttpRequest)
)
break

let data = try:
await rpc.route(req)
except CatchableError as exc:
debug "Internal error, while processing RPC call",
address = $request.uri
await ws.close(
reason = "Internal error, while processing RPC call: " & exc.msg
)
break
let data = await rpc.route(req)

trace "RPC result has been sent", address = $request.uri
await ws.send(data)

except WebSocketError as exc:
error "WebSocket error:", exception = exc.msg
error "WebSocket error:",
address = $request.uri, msg = exc.msg

except CancelledError as exc:
raise exc

except CatchableError as exc:
debug "Something error", msg=exc.msg
debug "Internal error while processing JSON-RPC call", msg=exc.msg

proc handleRequest(rpc: RpcWebSocketServer, request: HttpRequest)
{.async: (raises: [CancelledError]).} =
Expand Down

0 comments on commit 08a751b

Please sign in to comment.