@mantris/appify
Version:
Very opinionated Node.js API boilerplate as module.
34 lines (26 loc) • 611 B
JavaScript
const { TEST } = require('sugar-env')
const Sentry = require('@sentry/node')
/**
* @param {String} environment
* @param {Object<String, Function>} logger
* @returns {void}
*/
module.exports = function onUnhandledRejectionTrap (environment, logger) {
if (environment === TEST) {
return
}
process.on('unhandledRejection', (err) => {
logger.error(err)
const client = Sentry
.getCurrentHub()
.getClient()
if (!client) {
process.exit(1)
}
Sentry.captureException(err)
client
.close(3000)
.then(() => { process.exit(1) })
})
}