From 61205f33ec0a3c130e7ad29f1315b40ac3577873 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 7 Jul 2025 10:56:09 -0700 Subject: [PATCH] Add error handling for RPC response that returns OK but includes error details in the body. --- src/lib/rpc.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 { -- 2.47.3