Skip to content

Commit b22fe85

Browse files
authored
Report unhandledRejections and uncaughtExceptions to Sentry (#17014)
* Report to Sentry in error handlers * Support optional metadata
1 parent e85c2f8 commit b22fe85

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/failbot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = class FailBot {
7676
* @param {Error} error
7777
* @param {any} metadata
7878
*/
79-
async sendException (error, metadata) {
79+
async sendException (error, metadata = {}) {
8080
const data = Object.assign({ app: this.app }, this.getFailbotContext(), metadata)
8181
const body = this.formatJSON(error, Object.assign({ app: this.app }, data))
8282

lib/handle-exceptions.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
process.on('uncaughtException', err => {
1+
const FailBot = require('./failbot')
2+
3+
process.on('uncaughtException', async err => {
24
if (err.code === 'MODULE_NOT_FOUND') {
35
console.error('\n\n🔥 Uh oh! It looks you are missing a required npm module.')
46
console.error('Please run `npm install` to make sure you have all the required dependencies.\n\n')
57
}
68

79
console.error(err)
10+
await FailBot.report(err)
11+
})
12+
13+
process.on('unhandledRejection', async err => {
14+
console.error(err)
15+
await FailBot.report(err)
816
})

0 commit comments

Comments
 (0)