/** * Typed error hierarchy surfaced on the `error` channel of every ergonomic call (and * thrown when `throwOnError` is set). All are `Error` subclasses. Each concrete class * carries a literal `kind`, so {@link NeonErrorUnion} is a discriminated union: a * `kind` check narrows to that class. Every member extends {@link NeonError}, so * `instanceof NeonError` still matches all of them. */ import type { Operation } from "../client/types.gen.js"; export type NeonErrorKind = "api" | "not_found" | "auth" | "rate_limit" | "operation" | "timeout" | "aborted" | "network" | "client"; /** The `kind`s an HTTP-response error can carry. */ export type NeonApiErrorKind = "api" | "not_found" | "auth" | "rate_limit"; interface NeonApiErrorInit { status: number; code?: string; requestId?: string; response?: Response; body?: unknown; } /** * Base class for every error the ergonomic layer produces. * * Every subclass assigns `this.name` as a string literal rather than reading it from the * constructor. Bundlers rename classes, so deriving the name at runtime leaves consumers * of a minified build with errors called `s` and `r` — unreadable in logs and impossible * to group on in an error tracker. * * The SDK does not construct this class directly; it emits {@link NeonErrorUnion} members. */ export declare class NeonError extends Error { readonly kind: NeonErrorKind; constructor(message: string, kind: NeonErrorKind, options?: { cause?: unknown; }); } /** A non-2xx HTTP response from the Neon API. */ export declare class NeonApiError extends NeonError { readonly kind: NeonApiErrorKind; /** HTTP status code. */ readonly status: number; /** Machine-readable Neon error code (`GeneralError.code`), when present. */ readonly code?: string; /** Neon request id (`X-Request-Id` / `GeneralError.request_id`), when present. */ readonly requestId?: string; /** The raw response, when one was received. */ readonly response?: Response; /** The parsed error body, as returned by the API. */ readonly body: unknown; constructor(message: string, init: NeonApiErrorInit); } /** 404 — the resource does not exist. */ export declare class NeonNotFoundError extends NeonApiError { readonly kind: "not_found"; constructor(message: string, init: NeonApiErrorInit); } /** 401/403 — the API key is missing, invalid, or lacks permission. */ export declare class NeonAuthError extends NeonApiError { readonly kind: "auth"; constructor(message: string, init: NeonApiErrorInit); } /** 429 — rate limited (after retries, if enabled, were exhausted). */ export declare class NeonRateLimitError extends NeonApiError { readonly kind: "rate_limit"; constructor(message: string, init: NeonApiErrorInit); } /** An awaited Neon operation ended in a non-success terminal state. */ export declare class NeonOperationError extends NeonError { readonly kind: "operation"; /** The id of the operation that failed. */ readonly operationId: string; /** The terminal status reported by the API (`failed` / `error` / `cancelled`). */ readonly status: string; constructor(message: string, init: { operationId: string; status: string; }); } /** * A deadline was exceeded — either `requestTimeoutMs` for a request and its retries, or * the `wait` budget while polling operations for readiness. Not constructible: use * {@link NeonRequestTimeoutError} or {@link NeonWaitTimeoutError}. */ export declare abstract class NeonTimeoutError extends NeonError { readonly kind: "timeout"; abstract readonly source: "request" | "wait"; /** The budget that was exceeded, in ms. */ readonly timeoutMs: number; constructor(message: string, init: { timeoutMs: number; }); } /** `requestTimeoutMs` ran out. The call may never have reached the API. */ export declare class NeonRequestTimeoutError extends NeonTimeoutError { readonly source: "request"; constructor(message: string, init: { timeoutMs: number; }); } /** `wait.timeoutMs` ran out. The mutation was accepted; these operations were still running. */ export declare class NeonWaitTimeoutError extends NeonTimeoutError { readonly source: "wait"; /** Pass to `neon.operations.waitFor` to resume. Each carries `project_id`. */ readonly operations: readonly Operation[]; constructor(message: string, init: { timeoutMs: number; operations: readonly Operation[]; }); } /** * The caller's `AbortSignal` fired. Distinct from {@link NeonTimeoutError} because nothing * went wrong: the caller asked for the work to stop, and the two call for different * handling (retry a timeout, don't retry a cancellation). * * Raised only where the SDK knows the caller cancelled — the call's own deadline, or an * already-aborted `signal` on a raw call. A transport failure that merely looks like an * abort stays a {@link NeonNetworkError}, since the generated client reports auth, * serialization, interceptor and parsing faults through the same channel and an error's * name is not evidence about which one occurred. */ export declare class NeonAbortError extends NeonError { readonly kind: "aborted"; constructor(message: string, options?: { cause?: unknown; }); } /** A transport-level failure (DNS, connection, abort) — no HTTP response received. */ export declare class NeonNetworkError extends NeonError { readonly kind: "network"; /** * The most specific reason the platform gave for the failure — an `errno` code such as * `ECONNRESET` when one is available, otherwise the innermost non-empty message. Read * this instead of matching on {@link message}. */ readonly reason: string; constructor(message: string, options?: { cause?: unknown; reason?: string; }); } /** * A failure the SDK detected itself — an ambiguous connection-string selection, an * invalid `requestTimeoutMs`, a `noCompute` branch with compute settings, a response * missing a field the wrapper needs. `cause` is set when a lower-level error triggered it. */ export declare class NeonClientError extends NeonError { readonly kind: "client"; constructor(message: string, options?: { cause?: unknown; }); } /** * Every error the SDK emits, as a discriminated union on `kind`. This is the type of * `NeonResult`/`RawResult`'s `error` and of what `throwOnError` throws. Every member * extends {@link NeonError}, so `instanceof NeonError` still matches all of them. */ export type NeonErrorUnion = (NeonApiError & { readonly kind: "api"; }) | NeonNotFoundError | NeonAuthError | NeonRateLimitError | NeonOperationError | NeonRequestTimeoutError | NeonWaitTimeoutError | NeonAbortError | NeonNetworkError | NeonClientError; /** * Whether `error` is a member of {@link NeonErrorUnion}. Use this in a `catch` after * `throwOnError`: `instanceof NeonError` only yields the base class, whose `kind` does * not narrow. */ export declare function isNeonError(error: unknown): error is NeonErrorUnion; /** * Walk a transport failure's `cause` chain for the most specific description available. * * `fetch` reports every transport fault as `TypeError: fetch failed` and puts the real * reason underneath, sometimes several levels down and sometimes with an empty message and * only an `errno` code. Without this, a DNS failure, a reset connection and a redirect the * client refused to follow all produce the same sentence. */ export declare function describeTransportFailure(error: unknown): string; /** * Build the right {@link NeonError} subclass from a raw client result. `error` is the * decoded error body (Neon `GeneralError`); `response` is present unless the failure was * transport-level. */ export declare function toNeonError(error: unknown, response: Response | undefined): NeonErrorUnion; export {}; //# sourceMappingURL=errors.d.ts.map