From 0336da384fb09872f6bb6c0aadae9363493568fe Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 9 Jul 2025 16:20:38 +0200 Subject: [PATCH] Provide `error.code` to `InvokeError` We decide during onboarding to display different things based on the error code received from the backend. Due to the new `InvokeError` type we lost this `error.code` string. --- src/lib/invoke.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/invoke.ts b/src/lib/invoke.ts index 6c1e1b4c6..b2103193f 100644 --- a/src/lib/invoke.ts +++ b/src/lib/invoke.ts @@ -20,9 +20,11 @@ export async function invoke( */ class InvokeError extends Error { name = "InvokeError"; + code: string; - constructor(message: string) { + constructor(message: string, code = "Unknown Error") { super(message); + this.code = code; Error.captureStackTrace?.(this, InvokeError); } } @@ -41,7 +43,7 @@ async function withTestBackend( // eslint-disable-next-line @typescript-eslint/no-explicit-any return fn(cmd, args, options).catch((error: any) => { if (typeof error === "object" && error !== null && "message" in error) { - throw new InvokeError(String(error.message)); + throw new InvokeError(String(error.message), String(error.code)); } else { throw new InvokeError(`Invalid error object: ${error}`); } @@ -59,7 +61,7 @@ async function withTestBackend( const json = await response.json(); if (!response.ok) { if (typeof json === "object" && json !== null && "message" in json) { - throw new InvokeError(String(json.message)); + throw new InvokeError(String(json.message), String(json.code)); } else { throw new InvokeError(`Invalid error object: ${json}`); }