@cto.ai/ops
Version:
💻 CTO.ai Ops - The CLI built for Teams 🚀
48 lines (47 loc) • 1.49 kB
JavaScript
;
/**
* @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 errorSource_1 = require("../constants/errorSource");
const Feathers_1 = require("../services/Feathers");
const env_1 = require("../constants/env");
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) {
const api = new Feathers_1.FeathersClient();
await api
.create('/log/event', { 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;