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; /** * The `error` codes of the framework's validation, routing, body-parsing and * server error responses, so a client can tell them apart without parsing the * translated `message`. */ export declare const FRAMEWORK_ERROR_CODES: { /** 400: a `params:`/`request:`/`query:` schema rejected the input (also the Mongoose safety nets). */ readonly validationFailed: 'VALIDATION_FAILED'; /** 400: the URL path could not be decoded. */ readonly malformedUrl: 'MALFORMED_URL'; /** 400: the request body could not be parsed. */ readonly malformedBody: 'MALFORMED_BODY'; /** 404: no route matches the path. */ readonly notFound: 'NOT_FOUND'; /** 405: a route matches the path, but not the method. */ readonly methodNotAllowed: 'METHOD_NOT_ALLOWED'; /** 413: the request body exceeds the configured limits. */ readonly payloadTooLarge: 'PAYLOAD_TOO_LARGE'; /** 415: the route accepts none of the request's content type. */ readonly unsupportedContentType: 'UNSUPPORTED_CONTENT_TYPE'; /** 500: an error nothing in the error-handler registry resolved. */ readonly serverError: 'SERVER_ERROR'; }; /** * 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), or `error` for a 5xx. * Subclass for other statuses, or construct the base directly: * `new HttpError(402, 'Payment required')`. */ 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); } export declare class UnprocessableEntityError extends HttpError { constructor(message?: string | HttpErrorDetails); } export declare class TooManyRequestsError extends HttpError { constructor(message?: string | HttpErrorDetails); } export declare class InternalServerError extends HttpError { constructor(message?: string | HttpErrorDetails); } export declare class BadGatewayError extends HttpError { constructor(message?: string | HttpErrorDetails); } export declare class ServiceUnavailableError extends HttpError { constructor(message?: string | HttpErrorDetails); }