UNPKG

@cto.ai/ops

Version:

💻 CTO.ai - The CLI built for Teams 🚀

48 lines (47 loc) • 1.53 kB
"use strict"; /** * @author: Prachi Singh (prachi@hackcapital.com) * @date: Tuesday, 23rd April 2019 10:55:23 am * @lastModifiedBy: Prachi Singh (prachi@hackcapital.com) * @lastModifiedTime: Monday, 26th August 2019 4:19:13 pm * * DESCRIPTION: This hook is used for error handling * * @copyright (c) 2019 Hack Capital */ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const errorSource_1 = require("../constants/errorSource"); const env_1 = require("./../constants/env"); const axios_1 = tslib_1.__importDefault(require("axios")); const { UNEXPECTED } = errorSource_1.errorSource; /** * Error hook to handle the errors * * @export * @param {*} this * @param {{ err: Error }} options */ async function error(options) { const { accessToken } = options; if (accessToken) { await axios_1.default .post(`${env_1.OPS_API_HOST}analytics-service/private/events`, { metadata: options.err }, { headers: { Authorization: accessToken, }, }) .catch(err => { this.debug('%O', err); }); } const { extra, message } = options.err; if (extra && extra.source === UNEXPECTED) { this.log(`\n 😰 We've encountered a problem. Please try again or contact ${env_1.INTERCOM_EMAIL} and we'll do our best to help. \n`); process.exit(1); } this.log(`\n ${message}`); if (extra && extra.exit) process.exit(); } exports.default = error;