Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ const Email = require('./lib/email')
const oauth2Routes = require('./lib/oauth2Routes')
const get = require('lodash.get')
const request = require('request-promise-native')
const bugsnag = require('@bugsnag/js')

process.env.DEBUG = process.env.DEBUG || 'envoy*'

function unhandledExceptionHandler (err) {
logger.error('SDK', 'Caught unhandled async exception:', err)

if (global.bugsnagClient) {
global.bugsnagClient.notify(err)
}

process.exit()
}

Expand All @@ -24,10 +30,17 @@ function registerUnhandledExceptionHandler () {
global.isUnhandledExceptionHandlerRegistered = true
}

function initializeBugsnag() {
if (this.config.bugsnagKey) {
global.bugsnagClient = bugsnag(this.config.bugsnagKey)
}
}

function Platform (config) {
this.config = config || {}
this.config.key = this.config.key || process.env.ENVOY_PLUGIN_KEY
this.config.baseUrl = this.config.baseUrl || process.env.ENVOY_BASE_URL || 'https://app.envoy.com'
this.config.bugsnagKey = this.config.bugsnagKey || process.env.ENVOY_BUGSNAG_KEY
this._routes = {}
this._workers = {}
this._interceptors = {}
Expand All @@ -41,6 +54,7 @@ function Platform (config) {
self.registerWorker(name, handler)
})
registerUnhandledExceptionHandler()
initializeBugsnag()
}
Platform.prototype.handleError = function (event, e) {
if (event.name === 'event' || (event.name === 'route' && this.req.job)) {
Expand Down
Loading