1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const exception_handler_1 = require("./exception-handler");
|
4 | const DEFAULT_TEARDOWN = () => process.exit(1);
|
5 | class ExceptionsZone {
|
6 | static run(callback, teardown = DEFAULT_TEARDOWN) {
|
7 | try {
|
8 | callback();
|
9 | }
|
10 | catch (e) {
|
11 | this.exceptionHandler.handle(e);
|
12 | teardown(e);
|
13 | }
|
14 | }
|
15 | static async asyncRun(callback, teardown = DEFAULT_TEARDOWN) {
|
16 | try {
|
17 | await callback();
|
18 | }
|
19 | catch (e) {
|
20 | this.exceptionHandler.handle(e);
|
21 | teardown(e);
|
22 | }
|
23 | }
|
24 | }
|
25 | exports.ExceptionsZone = ExceptionsZone;
|
26 | ExceptionsZone.exceptionHandler = new exception_handler_1.ExceptionHandler();
|