export const SwappaErrorType = { MathError: "MathError", HydrationError: "HydrationError", } as const export type SwappaErrorTypeValue = typeof SwappaErrorType[keyof typeof SwappaErrorType]; export class SwappaError extends Error { constructor(private readonly _type: EType, message: string) { super(`Swappa${_type}: ${message}`); } public get type(): EType { return this._type; } public static is(e: unknown): e is SwappaError { if (!e || !(typeof e === 'object') || Array.isArray(e)) return false; return 'type' in e && typeof e.type === 'string' && e.type in SwappaErrorType; } } export class SwappaMathError extends SwappaError { constructor(message: string) { super(SwappaErrorType.MathError, message); } public static is(e: unknown): e is SwappaMathError { return SwappaError.is(e) && e.type === SwappaErrorType.MathError; } }