Classes

c
HttpError(
statusCode: number,
message: string,
details?: Readonly<Record<string, unknown>>,
cause?: Error
)

The framework's HTTP error type.

Functions

f
conflict(message: string): HttpError

Creates a 409 Conflict error.

f
defaultFormatter(error: Error): DefaultErrorBody

Framework-standard error formatter.

f
errorHandler(options?: ErrorHandlerOptions): MiddlewareFunction

Creates a global error-handler middleware.

f
forbidden(message: string): HttpError

Creates a 403 Forbidden error.

f
internalServerError(
message: string,
cause?: Error
): HttpError

Creates a 500 Internal Server Error error.

f
notFound(message: string): HttpError

Creates a 404 Not Found error.

f
notImplemented(message: string): HttpError

Creates a 501 Not Implemented error.

f
f
selectFormatter(format?: ErrorFormat | ErrorHandlerFormatter): ErrorHandlerFormatter

Resolve the error format configuration to a concrete formatter function.

f
serviceUnavailable(message: string): HttpError

Creates a 503 Service Unavailable error.

f
statusTitle(statusCode: number): string

Resolves the human-readable title for a status code, falling back to a generic title for codes outside the well-known set.

f
unauthorized(message: string): HttpError

Creates a 401 Unauthorized error.

f
validationError(
errors: readonly ValidationError[],
message?: string
): HttpError

Creates a 422 Unprocessable Entity error wrapping a list of validation failures.

f

Interfaces

I
DefaultErrorBody

The framework-standard error body shape.

I
ErrorHandlerOptions

Options for the errorHandler middleware factory.

  • format: ErrorFormat | ErrorHandlerFormatter

    The error body format: 'default', 'rfc9457', the deprecated 'rfc7807', or a custom formatter function. Defaults to 'default'.

  • includeStackTrace: boolean

    When true, the error stack trace is included in the response body. Never enable this in production — pass a config-derived boolean (e.g. config.get('NODE_ENV') === 'development'), never read process.env directly (AI_GUIDELINES §4.1). Defaults to false.

  • logErrors: boolean

    When true (the default), caught errors are logged at error level via the ILogger resolved from ctx.services — but only if a logger is registered. When no logger is present, logging is silently skipped.

  • maskInternalErrors: boolean

    When true (the default), a caught value that was not an HttpError and resolves to a status >= 500 is masked in the response: its detail/message becomes the status title ('Internal Server Error') and the raw message — which for a failed query carries the SQL and its bound parameter values — is dropped from the body. The log is unaffected: logErrors still records the unmasked error and its cause chain, so an operator loses nothing unless logErrors is also false, the configuration that already logs nothing.

  • respond: (
    error: HttpError,
    ctx: IRequestContext
    ) =>
    HandlerResult
    | undefined
    | Promise<HandlerResult | undefined>

    Lets the application write its own response for a caught error. The hook receives the normalized error after status hints, internal-error masking, and status resolution, so error.statusCode is safe to serve. Return a HandlerResult produced by ctx.response to use that response; it may resolve that result asynchronously. Return or resolve to undefined to fall through to the configured formatter unchanged.

I
HttpErrorInit

Options accepted by the HttpError constructor.

I
ProblemDetails

A Problem Details object as defined by RFC 9457.

I
ValidationError

A single validation failure carried by a 422 error.

Type Aliases

T
ErrorFormat = "default" | "rfc9457" | "rfc7807"

The built-in error format identifiers for @setu-ts/exceptions.

T
ErrorHandlerFormatter = (
error: Error,
ctx?: IRequestContext
) => Record<string, unknown>

A function that formats a thrown error into a serializable error body.

Variables

v
ERROR_TYPE_BASE: "https://setu-ts.dev/errors"

The canonical base URI for framework-produced problem type identifiers.

v
STATUS_TITLES: Readonly<Record<number, string>>

A human-readable title for a given HTTP status code. This is the single source of truth used by both the factory functions and the Problem Details formatters so the title field never drifts from the produced statusCode.

Usage

import * as Exception_factory_functions___HttpError___error_formatters__and_the_global_error_handler_middleware___This_is_a___plain_package____not_a_plugin____it_depends_on___setu_ts_common__only_and_exposes_types__factories__and_a_middleware_factory__Register_the_middleware_via_the_application_s_pipeline______typescript_import___errorHandler___from___setu_ts_exceptions____app_middleware_add_errorHandler___format___rfc9457________priority__0__name___error_handler____________Every_export_here_is_public_API_and_documented_in_PUBLIC_API_md__AI_GUIDELINES__10__ from "exceptions/src/index.ts";