aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets/src/ts/error_reporter.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-01-24 02:10:43 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-01-24 02:10:43 +0800
commitd965fdb11dfba5631c1f98ad3e309876c199999a (patch)
treeec10b7341707cfcc6841d1b5fcbf0d3852536a79 /packages/testnet-faucets/src/ts/error_reporter.ts
parent8a858501f2b633f47cec9576b25e6f99911bbc09 (diff)
downloaddexon-sol-tools-d965fdb11dfba5631c1f98ad3e309876c199999a.tar.gz
dexon-sol-tools-d965fdb11dfba5631c1f98ad3e309876c199999a.tar.zst
dexon-sol-tools-d965fdb11dfba5631c1f98ad3e309876c199999a.zip
Rename to testnet-faucets
Diffstat (limited to 'packages/testnet-faucets/src/ts/error_reporter.ts')
-rw-r--r--packages/testnet-faucets/src/ts/error_reporter.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/testnet-faucets/src/ts/error_reporter.ts b/packages/testnet-faucets/src/ts/error_reporter.ts
new file mode 100644
index 000000000..6865d3893
--- /dev/null
+++ b/packages/testnet-faucets/src/ts/error_reporter.ts
@@ -0,0 +1,40 @@
+import * as express from 'express';
+import rollbar = require('rollbar');
+
+import { configs } from './configs';
+import { utils } from './utils';
+
+export const errorReporter = {
+ setup() {
+ rollbar.init(configs.ROLLBAR_ACCESS_KEY, {
+ environment: configs.ENVIRONMENT,
+ });
+
+ rollbar.handleUncaughtExceptions(configs.ROLLBAR_ACCESS_KEY);
+
+ process.on('unhandledRejection', async (err: Error) => {
+ utils.consoleLog(`Uncaught exception ${err}. Stack: ${err.stack}`);
+ await this.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((resolve, reject) => {
+ rollbar.handleError(err, req, (rollbarErr: Error) => {
+ if (rollbarErr) {
+ utils.consoleLog(`Error reporting to rollbar, ignoring: ${rollbarErr}`);
+ reject(rollbarErr);
+ } else {
+ resolve();
+ }
+ });
+ });
+ },
+ errorHandler() {
+ return rollbar.errorHandler(configs.ROLLBAR_ACCESS_KEY);
+ },
+};