1
0
mirror of synced 2025-12-22 11:26:57 -05:00

Report unhandledRejections and uncaughtExceptions to Sentry (#17014)

* Report to Sentry in error handlers

* Support optional metadata
This commit is contained in:
Jason Etcovitch
2020-12-16 11:28:25 -05:00
committed by GitHub
parent e85c2f8360
commit b22fe856c8
2 changed files with 10 additions and 2 deletions

View File

@@ -76,7 +76,7 @@ module.exports = class FailBot {
* @param {Error} error * @param {Error} error
* @param {any} metadata * @param {any} metadata
*/ */
async sendException (error, metadata) { async sendException (error, metadata = {}) {
const data = Object.assign({ app: this.app }, this.getFailbotContext(), metadata) const data = Object.assign({ app: this.app }, this.getFailbotContext(), metadata)
const body = this.formatJSON(error, Object.assign({ app: this.app }, data)) const body = this.formatJSON(error, Object.assign({ app: this.app }, data))

View File

@@ -1,8 +1,16 @@
process.on('uncaughtException', err => { const FailBot = require('./failbot')
process.on('uncaughtException', async err => {
if (err.code === 'MODULE_NOT_FOUND') { if (err.code === 'MODULE_NOT_FOUND') {
console.error('\n\n🔥 Uh oh! It looks you are missing a required npm module.') 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('Please run `npm install` to make sure you have all the required dependencies.\n\n')
} }
console.error(err) console.error(err)
await FailBot.report(err)
})
process.on('unhandledRejection', async err => {
console.error(err)
await FailBot.report(err)
}) })