import type { Response } from 'express'; import mongoose from 'mongoose'; import type { FrameworkRequest } from './HttpServer.ts'; /** The `message` of every framework 500 response. */ export declare const serverErrorMessage: (req: FrameworkRequest) => string; /** The `message` of every framework field-error (400) response. */ export declare const validationFailedMessage: (req: FrameworkRequest) => string; /** Levels the registry may log a handled error at (winston leveled methods). */ export type ErrorLogLevel = 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly'; /** What a handler returns to produce a response; `null`/`undefined` = pass. */ export interface ErrorHandlerResult { status: number; body: unknown; /** Response headers, e.g. `{ 'Retry-After': '30' }` on a 429. */ headers?: Record; } /** Answer a resolved error: its headers, status and JSON body. */ export declare function sendErrorResult(res: Response, { status, body, headers }: ErrorHandlerResult): Response>; export type ErrorHandlerFn = (err: E, req: FrameworkRequest) => ErrorHandlerResult | null | undefined | Promise; /** A registered (class, handler, level) triple as stored by the registry. */ export interface RegisteredErrorHandler { errorClass: abstract new (...args: never[]) => Error; handler: ErrorHandlerFn; logLevel: ErrorLogLevel; } /** * Sanitize an error for the RESOLVED-branch log line. A raw Mongoose * `ValidationError`'s `.message` (and `.stack` header) interpolates the * rejected `{VALUE}`, so `logger.warn(err)` would leak the submission into * logs — and whatever ships them (Sentry, retention) — even after the 400 * body was sanitized. Rebuild a fresh `Error` that reuses the per-path * `safeValidationMessage` texts under the safe static prefix * (` validation failed`); its stack is minted here, input-free. * Anything else passes through untouched. The UNRESOLVED 500 path deliberately * keeps logging the original error in full: that branch is a server-side * defect, and the developer needs every detail. */ export declare function toLoggableError(err: unknown): unknown; /** * Safety net for an escaped Mongoose `ValidationError`: returns a per-field * `{ : message }` map ONLY when every failing model path is a field the * client actually sent — the keys of the validated `request` ∪ `query`, minus * the framework-injected `contentType` discriminant (see * `ControllerManager.#wrapHandlerEntry`). A nested path (`profile.name`) * matches on its first segment and is reported under the full path (the * client owns that subtree). Any renamed/internal path → `null`, so the * caller keeps the honest 500 and never leaks a non-public field name. * * Each message is rebuilt by `safeValidationMessage` from the validation * `kind` + constraint — the raw `err.errors[path].message` is NEVER used, so * the submitted value can't ride into the response or the log. */ export declare function matchedClientValidationErrors(err: mongoose.Error.ValidationError, req: FrameworkRequest): Record | null; /** * Safety net for a STANDALONE Mongoose `CastError` — the shape a path param * produces (`findById(req.params.id)` with a malformed id). A `CastError` is a * sibling of `ValidationError`, not a subclass, so * {@link matchedClientValidationErrors} structurally cannot see it, and its * failing path is an internal model field (`_id`) that must never be echoed. * * Returns `{ : message }` only when the rejected value is one the * client actually supplied — matched by VALUE against the path params and the * validated body/query, then reported under that public input name. A cast * failure on a server-computed value matches nothing and returns `null`, so a * genuine server-side defect keeps its honest 500 instead of being blamed on * the caller. The message comes from {@link safeValidationMessage}, so the * rejected value never rides into the response. */ export declare function matchedClientCastError(err: mongoose.Error.CastError, req: FrameworkRequest): Record | null; /** * Framework built-in registry entries, checked AFTER any consumer-registered * handlers ("yours win"): * 1. `HttpError` → its own status, headers and * `body ?? { error?: code, message }`, message translated via `i18nKey`; * `verbose` (deliberate control flow, not a defect). * 2. Escaped Mongoose `ValidationError` → the safety net above; `warn` * (signals a route schema missing a constraint the model enforces). * 3. Standalone Mongoose `CastError` → {@link matchedClientCastError}; `warn` * (signals a path param or input reaching the model unvalidated). Declaring * a route `params:` schema turns the same failure into a 400 earlier, with * a message you control. */ export declare function builtInErrorHandlers(): RegisteredErrorHandler[];