@nestjs/core
Version:
The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.
31 lines (30 loc) • 859 B
JavaScript
import { Logger } from '@nestjs/common';
import { ExceptionHandler } from './exception-handler.js';
const DEFAULT_TEARDOWN = () => process.exit(1);
export class ExceptionsZone {
static exceptionHandler = new ExceptionHandler();
static run(callback, teardown = DEFAULT_TEARDOWN, autoFlushLogs) {
try {
callback();
}
catch (e) {
this.exceptionHandler.handle(e);
if (autoFlushLogs) {
Logger.flush();
}
teardown(e);
}
}
static async asyncRun(callback, teardown = DEFAULT_TEARDOWN, autoFlushLogs) {
try {
await callback();
}
catch (e) {
this.exceptionHandler.handle(e);
if (autoFlushLogs) {
Logger.flush();
}
teardown(e);
}
}
}