From: Chris Duncan Date: Mon, 7 Jul 2025 17:56:09 +0000 (-0700) Subject: Add error handling for RPC response that returns OK but includes error details in... X-Git-Tag: v0.10.5~89 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=61205f33ec0a3c130e7ad29f1315b40ac3577873;p=libnemo.git Add error handling for RPC response that returns OK but includes error details in the body. --- diff --git a/src/lib/rpc.ts b/src/lib/rpc.ts index 0497a91..be6fc4c 100644 --- a/src/lib/rpc.ts +++ b/src/lib/rpc.ts @@ -49,11 +49,22 @@ export class Rpc { body }) const kill = setTimeout(() => { + console.log('aborting RPC call') aborter.abort() }, 10000) try { const res = await fetch(req) - return await res.json() + if (res.status !== 200) { + throw new Error(`${res.status} ${res.statusText}`) + } + const data = await res.json() + if (data.error != null) { + const msg = data.message == null + ? data.error + : `${data.error} ${data.message}` + throw new Error(msg) + } + return data } catch (err) { return JSON.stringify(err) } finally {