import * as _homer0_jimple from '@homer0/jimple'; import { J as Jimpex, D as MiddlewareConnectFn } from '../../index-DAUqbQ6h.js'; import { ExpressErrorHandler } from '../../types/express.js'; import { Statuses } from '../../utils/fns/statuses.js'; import { SimpleLogger } from '@homer0/simple-logger'; import { DeepPartial } from '../../types/utils.js'; import { HTTPErrorClass } from '../../services/common/httpError.js'; import { ResponsesBuilder } from '../../services/http/responsesBuilder.js'; import '../../types/http.js'; import 'https'; import 'http'; import 'spdy'; import 'node-fetch'; import 'express'; import '@homer0/path-utils'; import '@homer0/simple-config'; import '@homer0/events-hub'; import 'statuses'; import '../../services/common/appError.js'; /** * The options for the responses the middleware will create. * * @group Middlewares/ErrorHandler */ type ErrorHandlerResponseOptions = { /** * The message to show in case `showErrors` is set to `false`. * * @default 'Oops! Something went wrong, please try again' * @prettierignore */ message: string; /** * The default status code for the responses. * * @default 500 */ status: number; }; /** * The customization options for the middleware. * * @group Middlewares/ErrorHandler */ type ErrorHandlerOptions = { /** * If `false`, unknown errors will show a generic message instead of real message. And * if `true`, it will not only show all kind of errors but it will also show the error * stack. * * By "unknown errors", it means that are not `AppError` nor `HTTPError`. */ showErrors: boolean; /** * The options for the default response the middleware will create. */ response: ErrorHandlerResponseOptions; }; /** * A partial version of the {@link ErrorHandlerOptions}, to be used in the constructor and * the middleware creator. * * @group Middlewares/ErrorHandler */ type ErrorHandlerPartialOptions = DeepPartial; /** * The options to construct a {@link ErrorHandler}. * * @group Middlewares/ErrorHandler */ type ErrorHandlerConstructorOptions = ErrorHandlerPartialOptions & { /** * A dictionary with the dependencies to inject. */ inject: { logger: SimpleLogger; responsesBuilder: ResponsesBuilder; statuses: Statuses; HTTPError: HTTPErrorClass; }; }; /** * Creates a middleware that handles errors and generates the responses. * * @group Middleware Classes * @group Middlewares/ErrorHandler * @prettierignore */ declare class ErrorHandler { /** * The service that will log the messages in the console. */ protected readonly _logger: SimpleLogger; /** * The service to generate the responses. */ protected readonly _responsesBuilder: ResponsesBuilder; /** * The utility service to get HTTP status codes. */ protected readonly _statuses: Statuses; /** * The Error class used by the "known errors". */ protected readonly _HTTPError: HTTPErrorClass; /** * The customization options. */ protected readonly _options: ErrorHandlerOptions; /** * @param options The options to construct the class. */ constructor({ inject: { logger, responsesBuilder, statuses, HTTPError }, ...options }: ErrorHandlerConstructorOptions); /** * Generates the middleware that handles the errors. */ getMiddleware(): ExpressErrorHandler; /** * The handler customization options. */ get options(): Readonly; } /** * Creates the middleware that handles errors. * * @group Middlewares * @group Middlewares/ErrorHandler */ declare const errorHandlerMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: ErrorHandlerPartialOptions) => (app: ContainerType) => ExpressErrorHandler, MiddlewareConnectFn>; export { ErrorHandler, type ErrorHandlerConstructorOptions, type ErrorHandlerOptions, type ErrorHandlerPartialOptions, type ErrorHandlerResponseOptions, errorHandlerMiddleware };