import { FilesError } from "../errors.js"; import type { WireError, WireErrorCode, WireErrorReason, WireFilesError } from "../files-router/protocol.js"; /** * A failure the router itself raises (authorization, validation, origin) — as * opposed to a `FilesError` bubbling up from a `Files` call. Carries a wire code * and optional `reason` directly. */ export declare class RouterError extends Error { static [Symbol.hasInstance](value: unknown): boolean; readonly code: WireErrorCode; readonly reason?: WireErrorReason; /** HTTP status override (e.g. 413 for an oversized request); else derived from `code`. */ readonly status?: number; constructor(code: WireErrorCode, message: string, reason?: WireErrorReason, status?: number); } export declare const httpStatus: (code: WireErrorCode) => number; /** * Storage keys (and list prefixes) the request resolved, mapped to what the * client sent. A provider's error message names the storage key — authorize's * `keyPrefix` included — so the message is rewritten to the caller's own key * before it crosses the wire: one tenant never learns how its keys are laid * out in the bucket. */ export type KeyRedactions = ReadonlyMap; /** `message` with every resolved storage key replaced by the client's key. */ export declare const redactKeys: (message: string, redactions: KeyRedactions | undefined) => string; /** * Mark `error` as thrown by an app hook for the client to read: its message is * sent as-is (keys still redacted), even under a code whose adapter-raised * messages are withheld. Returns `error`, so a `catch` can rethrow the result. */ export declare const markClientFacing: (error: T) => T; /** * The message the client may read for `error`. The SDK's own refusals * (`Invalid`, `Unsupported`, `ReadOnly`) and an app hook's errors are sent * with every resolved storage key rewritten to the client's; anything a * provider answered gets the fixed message for its code. */ export declare const clientErrorMessage: (error: FilesError, redactions?: KeyRedactions) => string; /** Serialize a `FilesError` to the wire shape — the safe subset, no `cause`. */ export declare const serializeFilesError: (error: FilesError, redactions?: KeyRedactions) => WireFilesError; /** * What the client hears about a failure that is neither a `FilesError` nor a * `RouterError` — a bug, or a plain `Error` an app hook threw. Its message can * carry anything (a connection string, a SQL error), so it never crosses the * wire; the router's `onError` gets the original. */ export declare const INTERNAL_ERROR_MESSAGE = "internal server error"; /** * Whether the router's `onError` should get `cause`: a failure the client only * hears about generically, so its detail would otherwise be lost. That's * anything that isn't a `RouterError` or `FilesError`, plus a storage-layer * `Provider` or `Unauthorized` error (the backend failed, or refused the * gateway's own credentials) that wasn't a cancelled request. An app hook's * deliberate `FilesError` and a routine `NotFound`/`Conflict` aren't reported. */ export declare const isReportedError: (cause: unknown) => boolean; export interface ErrorResult { status: number; body: WireError; } /** * Map any thrown value to a wire error envelope + HTTP status. Anything other * than a `RouterError`/`FilesError` is a generic 500 — its message stays on the * server (see {@link INTERNAL_ERROR_MESSAGE}) — and a `FilesError`'s message is * filtered by {@link clientErrorMessage}. */ export declare const toErrorResult: (cause: unknown, redactions?: KeyRedactions) => ErrorResult; //# sourceMappingURL=envelope.d.ts.map