From b22fe856c8f7eb8c7161aa5bbce888f699592f08 Mon Sep 17 00:00:00 2001 From: Jason Etcovitch Date: Wed, 16 Dec 2020 11:28:25 -0500 Subject: [PATCH] Report unhandledRejections and uncaughtExceptions to Sentry (#17014) * Report to Sentry in error handlers * Support optional metadata --- lib/failbot.js | 2 +- lib/handle-exceptions.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/failbot.js b/lib/failbot.js index 7c16434101..969560642d 100644 --- a/lib/failbot.js +++ b/lib/failbot.js @@ -76,7 +76,7 @@ module.exports = class FailBot { * @param {Error} error * @param {any} metadata */ - async sendException (error, metadata) { + async sendException (error, metadata = {}) { const data = Object.assign({ app: this.app }, this.getFailbotContext(), metadata) const body = this.formatJSON(error, Object.assign({ app: this.app }, data)) diff --git a/lib/handle-exceptions.js b/lib/handle-exceptions.js index cf2f25a90b..a8cba4bb89 100644 --- a/lib/handle-exceptions.js +++ b/lib/handle-exceptions.js @@ -1,8 +1,16 @@ -process.on('uncaughtException', err => { +const FailBot = require('./failbot') + +process.on('uncaughtException', async err => { if (err.code === 'MODULE_NOT_FOUND') { console.error('\n\n🔥 Uh oh! It looks you are missing a required npm module.') console.error('Please run `npm install` to make sure you have all the required dependencies.\n\n') } console.error(err) + await FailBot.report(err) +}) + +process.on('unhandledRejection', async err => { + console.error(err) + await FailBot.report(err) })