1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const debug_1 = tslib_1.__importDefault(require("debug"));
|
5 | const errorSource_1 = require("../constants/errorSource");
|
6 | const Feathers_1 = require("./Feathers");
|
7 | const debug = debug_1.default('ops:ErrorService');
|
8 | const { UNEXPECTED } = errorSource_1.errorSource;
|
9 | class ErrorService {
|
10 | constructor(api = new Feathers_1.FeathersClient()) {
|
11 | this.api = api;
|
12 | this.log = console.log;
|
13 | this.handleError = async (inputs) => {
|
14 | const { accessToken, err } = inputs;
|
15 | if (accessToken) {
|
16 | const api = new Feathers_1.FeathersClient();
|
17 | await api
|
18 | .create('/log/event', { metadata: err }, {
|
19 | headers: {
|
20 | Authorization: accessToken,
|
21 | },
|
22 | })
|
23 | .catch(err => {
|
24 | debug('%O', err);
|
25 | this.log(`\n 😰 We've encountered a problem. Please try again or contact support@cto.ai and we'll do our best to help. \n`);
|
26 | process.exit(1);
|
27 | });
|
28 | }
|
29 | const { extra, message } = err;
|
30 | if (extra && extra.source === UNEXPECTED) {
|
31 | this.log(`\n 😰 We've encountered a problem. Please try again or contact support@cto.ai and we'll do our best to help. \n`);
|
32 | process.exit(1);
|
33 | }
|
34 | this.log(`\n ${message}`);
|
35 | if (extra && extra.exit)
|
36 | process.exit();
|
37 | };
|
38 | }
|
39 | }
|
40 | exports.ErrorService = ErrorService;
|