/** * Error normalization helpers: collapse the ubiquitous * `err instanceof Error ? err.message : String(err)` dance into a single * call, walk `cause` / `AggregateError` chains, and coerce any thrown * value into a real `Error`. Dependency-free and browser-safe. * * @module */ /** * Normalize any thrown value into an `Error`. Returns `value` unchanged * when it already is an `Error`, otherwise wraps its {@link errorMessage} * in a fresh `Error`. Use when a consumer needs a real `Error` object * (React error state, `reject`, rethrow) rather than just a printable * string. */ export declare function toError(value: unknown): Error; /** * Extract a human-readable message from any thrown value. Returns * `value.message` when `value` is an `Error`, otherwise coerces via * `String(value)`. Collapses the ubiquitous * * ```ts * err instanceof Error ? err.message : String(err) * ``` * * dance into a single helper, useful for log attributes and any other * "give me something printable" context. */ export declare function errorMessage(value: unknown): string; /** * Yield `message` / `errorCode` strings from every node in the error * tree (see {@link errorNodes}). Used by {@link errorMessage} and * message predicates elsewhere. */ export declare function errorMessages(value: unknown): Generator; /** * Depth-first walk of an error value: the root, then `errors` (e.g. * `AggregateError`) and `cause` chains. Cycle-safe via a `seen` set. */ export declare function errorNodes(err: unknown): Generator, void, undefined>; /** * Lazy view over a thrown value for HTTP-status + message classification. * Status comes from the last positive `statusCode` / `code` on the error tree; * messages/tokens come from every `message` / `errorCode` field (including * `cause` and `AggregateError.errors`). Build with {@link errorContext}. */ export type ErrorContext = ErrorContextImpl; declare class ErrorContextImpl { private readonly err; private _statusCode; private _messages; private _messageTokens; constructor(err: NonNullable); /** Last positive `statusCode` / `code` found on the error tree, else `undefined` (0 ignored). */ get statusCode(): number | undefined; /** Every `message` / `errorCode` string in the error tree. */ get messages(): string[]; /** Lowercased tokens from {@link messages}. */ get messageTokens(): string[]; /** True for any 4xx status or message tokens `not exist` / `not found`. */ get notAccessible(): boolean; /** * Match HTTP status. Pass a full code (`404`) or a class (`4` for any 4xx). * Extra filters are OR'd. `false` when no status is on the error tree. */ hasStatusCode(statusCodeFilter: number, ...statusCodeFilters: number[]): boolean; /** * True when every token from the filter phrase(s) appears in * {@link messageTokens}. Each argument is tokenized on non-alphanumeric * boundaries (e.g. `hasMessage("not", "found")` or `hasMessage("not found")`). */ hasMessage(messageFilter: string, ...messageFilters: string[]): boolean; } /** Build an {@link ErrorContext} for status + message checks. `null` / `undefined` become `{}`. */ export declare function errorContext(err: unknown): ErrorContext; export {};