UNPKG

830 BJavaScriptView Raw
1// Gigster
2const {AnalyticsService, ReportService} = require('@gigster/gig-services');
3
4
5const guard = async (callback) => {
6 try {
7 // Stub the console exit to protect the CLI.
8 // The Loopback generator does a process exit after 100ms!
9 process.death = process.exit;
10 process.exit = () => {};
11
12 await callback();
13 } catch (error) {
14 ReportService.reportError(error);
15
16 // eslint-disable-next-line
17 console.log(
18 `For help, please contact Gigster ` +
19 `via the '/dev-support' slack command.`);
20
21 // Exit with a non-zero status code.
22 // we use process.exitCode to make sure we exit only
23 // when done with all in progress IO work
24 // which gives rollbar the ability to flush the queue.
25 process.exitCode = 1;
26 }
27
28 AnalyticsService.flushSegment();
29};
30
31
32module.exports = guard;