]> git.codecow.com Git - libnemo.git/commitdiff
Add error handling for RPC response that returns OK but includes error details in...
authorChris Duncan <chris@zoso.dev>
Mon, 7 Jul 2025 17:56:09 +0000 (10:56 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 7 Jul 2025 17:56:09 +0000 (10:56 -0700)
src/lib/rpc.ts

index 0497a918c4329b07819f5db1cded4fcd58247b23..be6fc4c030abd8195bb77fd6b35c73a615553ad2 100644 (file)
@@ -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 {