UNPKG

1.65 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const debug_1 = tslib_1.__importDefault(require("debug"));
5const errorSource_1 = require("../constants/errorSource");
6const Feathers_1 = require("./Feathers");
7const debug = debug_1.default('ops:ErrorService');
8const { UNEXPECTED } = errorSource_1.errorSource;
9class 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}
40exports.ErrorService = ErrorService;