Skip to content

Commit

Permalink
server side error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Mar 21, 2024
1 parent 7c6ae58 commit 672f0b0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions waku/waku_store/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,21 @@ proc handleQueryRequest*(

proc initProtocolHandler(self: WakuStore) =
proc handler(conn: Connection, proto: string) {.async, gcsafe, closure.} =
let reqBuf = await conn.readLp(MaxRpcSize.int)
let readRes = catch:
await conn.readLp(MaxRpcSize.int)

let reqBuf = readRes.valueOr:
error "Connection read error", error = error.msg
return

let resBuf = await self.handleQueryRequest(conn.peerId, reqBuf)

await conn.writeLp(resBuf)
let writeRes = catch:
await conn.writeLp(resBuf)

if writeRes.isErr():
error "Connection write error", error = writeRes.error.msg
return

self.handler = handler
self.codec = WakuStoreCodec
Expand Down

0 comments on commit 672f0b0

Please sign in to comment.