UNPKG

1.49 kBJavaScriptView Raw
1"use strict";
2/**
3 * @author: Prachi Singh (prachi@hackcapital.com)
4 * @date: Tuesday, 23rd April 2019 10:55:23 am
5 * @lastModifiedBy: Prachi Singh (prachi@hackcapital.com)
6 * @lastModifiedTime: Monday, 26th August 2019 4:19:13 pm
7 *
8 * DESCRIPTION: This hook is used for error handling
9 *
10 * @copyright (c) 2019 Hack Capital
11 */
12Object.defineProperty(exports, "__esModule", { value: true });
13const errorSource_1 = require("../constants/errorSource");
14const Feathers_1 = require("../services/Feathers");
15const env_1 = require("../constants/env");
16const { UNEXPECTED } = errorSource_1.errorSource;
17/**
18 * Error hook to handle the errors
19 *
20 * @export
21 * @param {*} this
22 * @param {{ err: Error }} options
23 */
24async function error(options) {
25 const { accessToken } = options;
26 if (accessToken) {
27 const api = new Feathers_1.FeathersClient();
28 await api
29 .create('/log/event', { metadata: options.err }, {
30 headers: {
31 Authorization: accessToken,
32 },
33 })
34 .catch(err => {
35 this.debug('%O', err);
36 });
37 }
38 const { extra, message } = options.err;
39 if (extra && extra.source === UNEXPECTED) {
40 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`);
41 process.exit(1);
42 }
43 this.log(`\n ${message}`);
44 if (extra && extra.exit)
45 process.exit();
46}
47exports.default = error;