/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/core/errors/exceptions-zone.ts
40 строк
890 B
Micael Levi L. Cavalcante
fix(core): auto flush logs on synchronous internal errors
07 апр 2024, 19:43
07 апр 2024, 19:43
bc9755a
Код
Авторство
О чём код?
import { Logger } from '@nestjs/common'; import { ExceptionHandler } from './exception-handler'; const DEFAULT_TEARDOWN = () => process.exit(1); export class ExceptionsZone { private static readonly exceptionHandler = new ExceptionHandler(); public static run( callback: () => void, teardown: (err: any) => void = DEFAULT_TEARDOWN, autoFlushLogs: boolean, ) { try { callback(); } catch (e) { this.exceptionHandler.handle(e); if (autoFlushLogs) { Logger.flush(); } teardown(e); } } public static async asyncRun( callback: () => Promise<void>, teardown: (err: any) => void = DEFAULT_TEARDOWN, autoFlushLogs: boolean, ) { try { await callback(); } catch (e) { this.exceptionHandler.handle(e); if (autoFlushLogs) { Logger.flush(); } teardown(e); } } }