import { ConstructiveError } from './error'; import type { ParsedError } from './types'; /** * Normalize an error from any source (a {@link ConstructiveError}, a node-postgres * `DatabaseError`, a GraphQL error or `{ errors: [...] }` wrapper, a plain * `Error`, or a string) into a canonical {@link ParsedError}. * * Resolution order for the code: * 1. structured `DETAIL` JSON (`{ code, context }`) — Constructive's DB transport * 2. GraphQL `extensions.code` * 3. a leading ALL_CAPS token in the message (legacy DB `RAISE`), with any * `(arg, arg)` positional args mapped onto named context via the registry * 4. native SQLSTATE constraint mapping (23505 → `UNIQUE_VIOLATION`, …) * * Classification trusts an explicit `class` provided by the producer — the * database transport's `DETAIL.class` or the server's `extensions.class` — when * present, since that source is authoritative for the raise site (and correctly * classifies codes not yet in the registry). It falls back to `classify(code)` * (registry lookup, unknown ⇒ `internal`) only when no explicit class is given. */ export declare function parse(error: unknown): ParsedError; /** * Normalize any error into a throwable {@link ConstructiveError}. * * Delegates to {@link parse} for code/context/class recovery, then resolves a * localized message from the registry catalogs (falling back to the source * error's raw message when the code is unknown) and the registry's HTTP hint. * Codes that could not be resolved become `UNKNOWN_ERROR` (internal); a code * with no registered status is reported by {@link httpStatusFor} rather than * quietly becoming a 500. */ export declare function toError(error: unknown, locale?: string): ConstructiveError;