]> git.codecow.com Git - libnemo.git/commitdiff
Wrap RPC call to catch network errors.
authorChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 21:06:40 +0000 (14:06 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 3 Aug 2026 21:06:40 +0000 (14:06 -0700)
src/lib/block/index.ts

index 07c6c4a17860b7d6027c4d34982d9c696f0a989a..a214faf0bec84931b5e6d3c1d56a0fcea1a0f7fb 100644 (file)
@@ -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
        }
 
        /**