UNPKG

@cto.ai/ops

Version:

💻 CTO.ai Ops - The CLI built for Teams 🚀

41 lines (40 loc) • 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const debug_1 = tslib_1.__importDefault(require("debug")); const errorSource_1 = require("../constants/errorSource"); const Feathers_1 = require("./Feathers"); const debug = debug_1.default('ops:ErrorService'); const { UNEXPECTED } = errorSource_1.errorSource; class ErrorService { constructor(api = new Feathers_1.FeathersClient()) { this.api = api; this.log = console.log; this.handleError = async (inputs) => { const { accessToken, err } = inputs; if (accessToken) { const api = new Feathers_1.FeathersClient(); await api .create('/log/event', { metadata: err }, { headers: { Authorization: accessToken, }, }) .catch(err => { debug('%O', err); 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`); process.exit(1); }); } const { extra, message } = err; if (extra && extra.source === UNEXPECTED) { 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`); process.exit(1); } this.log(`\n ${message}`); if (extra && extra.exit) process.exit(); }; } } exports.ErrorService = ErrorService;