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:
1 parent
41fee50c55
commit
dc368962f4
1 file changed
+8
-1
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user