import type { ApiEnvelope } from "@owlboard/api-schema-types"; type RawErrorObject = NonNullable; export type ApiErrorCode = NonNullable export class ApiError extends Error { public readonly code: ApiErrorCode; public readonly status: number; constructor(errorObj: RawErrorObject, status: number) { super(errorObj.msg || 'An unknown error occurred'); this.name = 'ApiError'; this.status = status; // cast fallback to ensure it satisfies union this.code = errorObj.code || ("SERVER" as ApiErrorCode); } } export class ValidationError extends Error { constructor(public field: string, public reason: string) { super(`validation failed for ${field}: ${reason}`); this.name = "VALIDATIONERROR"; } }