blob: 49c37b6ebf8aff48df0fb5c5587290762ec9dde3 (
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
|
import { logUtils } from '@0xproject/utils';
import * as express from 'express';
import rollbar = require('rollbar');
import { configs } from './configs';
export const errorReporter = {
setup(): void {
rollbar.init(configs.ROLLBAR_ACCESS_KEY, {
environment: configs.ENVIRONMENT,
});
rollbar.handleUncaughtExceptions(configs.ROLLBAR_ACCESS_KEY);
process.on('unhandledRejection', async (err: Error) => {
logUtils.log(`Uncaught exception ${err}. Stack: ${err.stack}`);
await errorReporter.reportAsync(err);
process.exit(1);
});
},
async reportAsync(err: Error, req?: express.Request): Promise<any> {
if (configs.ENVIRONMENT === 'development') {
return; // Do not log development environment errors
}
return new Promise<any>((resolve, reject) => {
rollbar.handleError(err, req, (rollbarErr: Error) => {
if (rollbarErr) {
logUtils.log(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
reject(rollbarErr);
} else {
resolve();
}
});
});
},
errorHandler(): any {
return rollbar.errorHandler(configs.ROLLBAR_ACCESS_KEY);
},
};
|