1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ExceptionsZone = void 0;
|
4 | const common_1 = require("@nestjs/common");
|
5 | const exception_handler_1 = require("./exception-handler");
|
6 | const DEFAULT_TEARDOWN = () => process.exit(1);
|
7 | class 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 | }
|
33 | exports.ExceptionsZone = ExceptionsZone;
|
34 | ExceptionsZone.exceptionHandler = new exception_handler_1.ExceptionHandler();
|