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.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 23:05:00 -04:00
1 parent 41fee50c55
commit dc368962f4
1 file changed
+8 -1
+8 -1
View File
@@ -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<T>(result: DesktopResult<T>): T {
if (!result.ok) {
throw new Error(result.error.message);
throw new DesktopError(result.error.code, result.error.message);
}
return result.data;
}