import type { ValidationIssue } from '../validate/types.ts'; import { type ValidationErrorPayload } from '../validate/ValidationError.ts'; /** Contract form: answered as `{ error?: code, message, errors? }`; `i18nKey` stays on the server. */ export interface HttpErrorContractDetails { /** English text: the log line, and the response message unless `i18nKey` translates it. */ message: string; /** Machine-readable code, answered as `{ error: code, message }`. */ code?: string; /** Translation key for the response message; stays on the server. */ i18nKey?: string; /** * Field errors, the same shape as request validation: `{ field: msg | [msg] }` * or validation issues (with `params` for interpolation). Answered as * `errors: { field: [msg] }`; i18n-key messages are translated. */ errors?: ValidationErrorPayload | ReadonlyArray; /** Response headers, e.g. `{ 'Retry-After': '30' }` on a 429. */ headers?: Record; body?: never; } /** Custom form: `body` IS the response — the contract fields cannot be combined with it. */ export interface HttpErrorBodyDetails { /** English text for the log line; not sent. */ message: string; /** The whole response body, sent as-is (no `error`/`message`/`errors` added). */ body: unknown; /** Response headers, e.g. `{ 'Retry-After': '30' }` on a 429. */ headers?: Record; code?: never; i18nKey?: never; errors?: never; } export type HttpErrorDetails = HttpErrorContractDetails | HttpErrorBodyDetails; /** * Throwable HTTP errors — the deliberate way to produce a status from deep * business logic without threading `res`. Thrown from a route handler or a * middleware, they resolve through the error-handler registry * (`HttpServer.registerErrorHandler`) via a built-in mapper: * `status` + `{ error?: code, message, errors? }` (message translated via * `i18nKey`, field errors like request validation) or a custom `body`, logged * at `verbose` (control flow, not a defect). * Subclass for other statuses, or construct the base directly: * `new HttpError(422, 'Unprocessable')`. */ export declare class HttpError extends Error { readonly status: number; /** Custom response body (`{ message, body }`); when set, the contract fields are unused. */ readonly body?: unknown; readonly code?: string; readonly i18nKey?: string; /** Field errors from `details.errors`, normalized to validation issues. */ readonly issues?: ReadonlyArray; /** Response headers from `details.headers`. */ readonly headers?: Record; constructor(status: number, message: string | HttpErrorDetails); /** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */ constructor(status: number, message: string | HttpErrorDetails, body: unknown); } export declare class BadRequestError extends HttpError { constructor(message?: string | HttpErrorDetails); /** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */ constructor(message: string | HttpErrorDetails | undefined, body: unknown); } export declare class UnauthorizedError extends HttpError { constructor(message?: string | HttpErrorDetails); /** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */ constructor(message: string | HttpErrorDetails | undefined, body: unknown); } export declare class ForbiddenError extends HttpError { constructor(message?: string | HttpErrorDetails); /** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */ constructor(message: string | HttpErrorDetails | undefined, body: unknown); } export declare class NotFoundError extends HttpError { constructor(message?: string | HttpErrorDetails); /** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */ constructor(message: string | HttpErrorDetails | undefined, body: unknown); } export declare class ConflictError extends HttpError { constructor(message?: string | HttpErrorDetails); /** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */ constructor(message: string | HttpErrorDetails | undefined, body: unknown); }