UNPKG

1.05 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ExceptionsZone = void 0;
4const common_1 = require("@nestjs/common");
5const exception_handler_1 = require("./exception-handler");
6const DEFAULT_TEARDOWN = () => process.exit(1);
7class ExceptionsZone {
8 static run(callback, teardown = DEFAULT_TEARDOWN, autoFlushLogs) {
9 try {
10 callback();
11 }
12 catch (e) {
13 this.exceptionHandler.handle(e);
14 if (autoFlushLogs) {
15 common_1.Logger.flush();
16 }
17 teardown(e);
18 }
19 }
20 static async asyncRun(callback, teardown = DEFAULT_TEARDOWN, autoFlushLogs) {
21 try {
22 await callback();
23 }
24 catch (e) {
25 this.exceptionHandler.handle(e);
26 if (autoFlushLogs) {
27 common_1.Logger.flush();
28 }
29 teardown(e);
30 }
31 }
32}
33exports.ExceptionsZone = ExceptionsZone;
34ExceptionsZone.exceptionHandler = new exception_handler_1.ExceptionHandler();