From: Chris Duncan Date: Mon, 3 Aug 2026 21:06:40 +0000 (-0700) Subject: Wrap RPC call to catch network errors. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=896275c9fadd660fe26be772d98219cd8a899010;p=libnemo.git Wrap RPC call to catch network errors. --- diff --git a/src/lib/block/index.ts b/src/lib/block/index.ts index 07c6c4a..a214faf 100644 --- a/src/lib/block/index.ts +++ b/src/lib/block/index.ts @@ -209,11 +209,15 @@ export class Block { json_block: true, block: this.toJSON() } - const res = await rpc.post('process', data) - if (res == null || typeof res !== 'object' || !('hash' in res) || typeof res.hash !== 'string') { - throw new Error('Block could not be processed', { cause: res }) + try { + const res = await rpc.post('process', data) + if (res == null || typeof res !== 'object' || !('hash' in res) || typeof res.hash !== 'string') { + throw new Error('RPC process request received incomplete response', { cause: res }) + } + return res.hash + } catch (err) { + throw new Error('Block could not be processed', { cause: err }) } - return res.hash } /**