/** * HTTP-aware error types and the default error renderer. * * Throw an `HttpError` (or one of its named subclasses) from a handler or guard * and the framework turns it into a JSON response with the right status. Anything * that isn't an `HttpError` becomes a `500`. Register an error handler * (`@catchError` / `createApp({ onError })`) to customize any of this. */ export interface HttpErrorOptions { /** A stable, machine-readable error code (e.g. `"user_not_found"`). */ code?: string; /** Extra structured data to include in the response body. */ details?: unknown; /** The underlying error, for logging/`cause` chaining. */ cause?: unknown; } /** The JSON body shape produced by the default error renderer (the `problemDetails()` plugin replaces it with RFC 9457). */ export interface ErrorBody { /** The error envelope; `code`/`details` are omitted from the body when unset, not sent as `undefined`. */ error: { message: string; code?: string; details?: unknown; }; } /** * An error carrying an HTTP status. Throw it from a handler/guard to short-circuit * with that status; the framework renders it via {@link HttpError.toResponse}. * Extend it for domain errors, or throw `new HttpError(status, message)` directly. */ export declare class HttpError extends Error { /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** `message` defaults to `HTTP `; `.name` is set to the concrete subclass (e.g. `"NotFoundError"`), and `cause` is chained onto the underlying `Error`. */ constructor(status: number, message?: string, options?: HttpErrorOptions); /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; } /** `400 Bad Request` */ export declare const BadRequestError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `401 Unauthorized` */ export declare const UnauthorizedError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `402 Payment Required` */ export declare const PaymentRequiredError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `403 Forbidden` */ export declare const ForbiddenError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `404 Not Found` */ export declare const NotFoundError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `409 Conflict` */ export declare const ConflictError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `410 Gone` */ export declare const GoneError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `422 Unprocessable Entity` (e.g. validation failures) */ export declare const UnprocessableEntityError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `429 Too Many Requests` */ export declare const TooManyRequestsError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** `500 Internal Server Error` */ export declare const InternalServerError: { new (message?: string, options?: HttpErrorOptions): { name: string; message: string; stack?: string; /** The HTTP status code sent for this error. */ readonly status: number; /** Optional stable, machine-readable error code. */ readonly code?: string; /** Optional structured data included in the response body. */ readonly details?: unknown; /** * Render this error as a JSON `Response` with its status. * * @returns a JSON `Response` carrying this error's status and `{ error }` body */ toResponse(): Response; cause?: unknown; }; captureStackTrace(targetObject: object, constructorOpt?: Function): void; captureStackTrace(targetObject: object, constructorOpt?: Function): void; prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; stackTraceLimit: number; isError(value: unknown): value is Error; }; /** * The default rendering for an unhandled thrown value: an `HttpError` (or a * subclass) becomes its `toResponse()`, a thrown `Response` passes through, and * anything else becomes an opaque `500` (its message is not leaked to the client). * * @param err - the thrown value to render * @returns the corresponding `Response` */ export declare function toErrorResponse(err: unknown): Response; //# sourceMappingURL=error.d.ts.map