aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils/error_reporter.ts
blob: a9731c4d49dca857e2017aedb5f4d79818e03d64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {utils} from 'ts/utils/utils';
import {constants} from 'ts/utils/constants';
import {configs} from 'ts/utils/configs';
import {Environments} from 'ts/types';

// Suggested way to include Rollbar with Webpack
// https://github.com/rollbar/rollbar.js/tree/master/examples/webpack
const rollbarConfig = {
    accessToken: constants.ROLLBAR_ACCESS_TOKEN,
    captureUncaught: true,
    captureUnhandledRejections: true,
    itemsPerMinute: 10,
    maxItems: 500,
    payload: {
        environment: configs.ENVIRONMENT,
    },
    uncaughtErrorLevel: 'error',
    hostWhiteList: [constants.PRODUCTION_DOMAIN, constants.STAGING_DOMAIN],
    ignoredMessages: [
        // Errors from the third-party scripts
        'Script error',
        // Network errors or ad-blockers
        'TypeError: Failed to fetch',
        'Exchange has not been deployed to detected network (network/artifact mismatch)',
        // Source: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/7VU0_VvC7mE
        'undefined is not an object (evaluating \'__gCrWeb.autofill.extractForms\')',
        // Source: http://stackoverflow.com/questions/43399818/securityerror-from-facebook-and-cross-domain-messaging
        'SecurityError (DOM Exception 18)',
    ],
};
import Rollbar = require('../../public/js/rollbar.umd.nojson.min.js');
const rollbar = Rollbar.init(rollbarConfig);

export const errorReporter = {
    reportAsync(err: Error): Promise<any> {
        if (configs.ENVIRONMENT === Environments.DEVELOPMENT) {
            return; // Let's not log development errors to rollbar
        }

        return new Promise((resolve, reject) => {
            rollbar.error(err, (rollbarErr: Error) => {
                if (rollbarErr) {
                    utils.consoleLog(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
                    // We never want to reject and cause the app to throw because of rollbar
                    resolve();
                } else {
                    resolve();
                }
            });
        });
    },
};