From dc368962f46924b786a6eb59b9e80d5f2dd2ecdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 23:05:00 -0400 Subject: [PATCH] feat(desktop): preserve error.code via DesktopError class in unwrap (P3-52) Callers can now catch DesktopError and inspect err.code to distinguish auth/validation/unknown failures; plain Error fallback kept for message. --- src/renderer/lib/desktop.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/renderer/lib/desktop.ts b/src/renderer/lib/desktop.ts index c75a8817..386c2360 100644 --- a/src/renderer/lib/desktop.ts +++ b/src/renderer/lib/desktop.ts @@ -1,8 +1,15 @@ import type { DesktopResult } from "@shared/contracts"; +export class DesktopError extends Error { + constructor(public readonly code: string, message: string) { + super(message); + this.name = "DesktopError"; + } +} + export function unwrap(result: DesktopResult): T { if (!result.ok) { - throw new Error(result.error.message); + throw new DesktopError(result.error.code, result.error.message); } return result.data; }