UNPKG

@cto.ai/ops

Version:

💻 CTO.ai - The CLI built for Teams 🚀

41 lines (40 loc) • 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorService = void 0; const tslib_1 = require("tslib"); const debug_1 = tslib_1.__importDefault(require("debug")); const axios_1 = tslib_1.__importDefault(require("axios")); const errorSource_1 = require("../constants/errorSource"); const env_1 = require("./../constants/env"); const debug = (0, debug_1.default)('ops:ErrorService'); const { UNEXPECTED } = errorSource_1.errorSource; class ErrorService { constructor() { this.log = console.log; this.handleError = async (inputs) => { const { accessToken, err } = inputs; if (accessToken) { await axios_1.default .post(`${env_1.OPS_API_HOST}analytics-service/private/events`, { 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;