aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/error_reporter.ts
blob: 81a90e7f5a226b29342004d8face3619c341a1ef (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { logUtils } from '@0x/utils';

import { ROLLBAR_CLIENT_TOKEN, ROLLBAR_ENVIRONMENT } from '../constants';

// Import version of Rollbar designed for embedded components
// See https://docs.rollbar.com/docs/using-rollbarjs-inside-an-embedded-component
// tslint:disable-next-line:no-var-requires
const Rollbar = require('rollbar/dist/rollbar.noconflict.umd');

const shouldAllowRollbar = () => {
    if (ROLLBAR_ENVIRONMENT === 'development') {
        return process.env.ROLLBAR_FORCE_DEVELOPMENT_REPORT ? true : false;
    }
    return true;
};

let rollbar: any;
if (ROLLBAR_CLIENT_TOKEN && ROLLBAR_ENVIRONMENT && shouldAllowRollbar()) {
    rollbar = new Rollbar({
        accessToken: ROLLBAR_CLIENT_TOKEN,
        captureUncaught: true,
        captureUnhandledRejections: true,
        enabled: true,
        itemsPerMinute: 10,
        maxItems: 500,
        payload: {
            environment: ROLLBAR_ENVIRONMENT,
            client: {
                javascript: {
                    source_map_enabled: true,
                    code_version: process.env.GIT_SHA,
                    guess_uncaught_frames: true,
                },
            },
        },
        uncaughtErrorLevel: 'error',
        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)',
        ],
    });
}

export const setupRollbar = (): any => {
    return rollbar as any;
};

export const errorReporter = {
    report(err: Error): void {
        if (!rollbar) {
            logUtils.log('Not reporting to rollbar because not configured', err);
            return;
        }

        rollbar.error(err, (rollbarErr: Error) => {
            if (rollbarErr) {
                logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
            }
        });
    },
};