UNPKG

kitcn

Version:

kitcn - React Query integration and CLI tools for Convex

41 lines (40 loc) 1.52 kB
//#region src/crpc/error.ts /** * Client-side CRPC error. * Mirrors backend CRPCError pattern with typed error codes. */ var CRPCClientError = class extends Error { name = "CRPCClientError"; code; functionName; constructor(opts) { super(opts.message ?? `${opts.code}: ${opts.functionName}`); this.code = opts.code; this.functionName = opts.functionName; } }; /** Type guard for CRPCClientError */ const isCRPCClientError = (error) => error instanceof CRPCClientError; /** * Unified check for any deterministic CRPC error (Convex or HTTP). * Use in retry logic to skip retrying client errors (4xx). */ const isCRPCError = (error) => { if (error instanceof CRPCClientError) return true; if (error instanceof Error && error.name === "HttpClientError" && "status" in error && typeof error.status === "number") return error.status < 500; return false; }; /** Type guard for specific error code */ const isCRPCErrorCode = (error, code) => isCRPCClientError(error) && error.code === code; /** Default unauthorized detection - checks UNAUTHORIZED code */ const defaultIsUnauthorized = (error) => { if (!error || typeof error !== "object") return false; if ("data" in error) { const data = error.data; if (data && typeof data === "object" && "code" in data) return data.code === "UNAUTHORIZED"; } if ("code" in error) return error.code === "UNAUTHORIZED"; return false; }; //#endregion export { isCRPCErrorCode as a, isCRPCError as i, defaultIsUnauthorized as n, isCRPCClientError as r, CRPCClientError as t };