export type Logger = import('./logger').Logger; export type ProviderCreator = import('../shared/jimpleFns').ProviderCreator; export type ErrorHandlerServiceMap = { /** * A list of loggers' service names from * which the service will try to find the * first available, * a specific service name, or an * instance of {@link Logger }. */ logger?: string[] | string | Logger; }; export type ErrorHandlerProviderOptions = { /** * The name that will be used to register * an instance of {@link ErrorHandler }. * Its default value is `errorHandler`. */ serviceName: string; /** * Whether or not to exit the process * after receiving an error. */ exitOnError: boolean; /** * A dictionary with the services that * need to be injected on the class. */ services: ErrorHandlerServiceMap; }; /** * @module node/errorHandler */ /** * @typedef {import('./logger').Logger} Logger */ /** * @typedef {import('../shared/jimpleFns').ProviderCreator} ProviderCreator * @template O */ /** * @typedef {Object} ErrorHandlerServiceMap * @property {string[] | string | Logger} [logger] A list of loggers' service names from * which the service will try to find the * first available, * a specific service name, or an * instance of {@link Logger}. * @parent module:node/errorHandler */ /** * @typedef {Object} ErrorHandlerProviderOptions * @property {string} serviceName The name that will be used to register * an instance of {@link ErrorHandler}. * Its default value is `errorHandler`. * @property {boolean} exitOnError Whether or not to exit the process * after receiving an error. * @property {ErrorHandlerServiceMap} services A dictionary with the services that * need to be injected on the class. * @parent module:node/errorHandler */ /** * An error handler that captures uncaught exceptions and unhandled rejections in order to * log them with detail. * * @parent module:node/errorHandler * @tutorial errorHandler */ export class ErrorHandler { /** * @param {Logger} appLogger To log the detail of the erros. * @param {boolean} [exitOnError=true] Whether or not to exit the process after * receiving an error. */ constructor(appLogger: Logger, exitOnError?: boolean); /** * A local reference for the `appLogger` service. * * @type {Logger} * @access protected * @ignore */ _appLogger: Logger; /** * Whether or not to exit the process after receiving an error. * * @type {boolean} * @access protected * @ignore */ _exitOnError: boolean; /** * The list of events this handler will listen for in order to catch errors. * * @type {string[]} * @access protected * @ignore */ _eventsNames: string[]; /** * Bind the handler method so it can be used on the calls to `process`. * * @ignore */ handler: any; /** * This is called by the process listeners when an uncaught exception is thrown or a * rejected promise is not handled. It logs the error on detail. * The process exits when after logging an error. * * @param {Error} error The unhandled error. */ handle(error: Error): void; /** * Starts listening for unhandled errors. */ listen(): void; /** * Stops listening for unhandled errors. */ stopListening(): void; /** * Whether or not the process will exit after receiving an error. * * @type {boolean} */ get exitOnError(): boolean; } /** * The service provider to register an instance of {@link ErrorHandler} on the container. * * @type {ProviderCreator} * @throws {Error} * If `services.logger` specifies a service that doesn't exist or if it's a falsy value. * @tutorial errorHandler */ export const errorHandler: ProviderCreator;