Make mixpanelTrack nicely handle errors being passed in and use it for logging bootstrapping errors.

This commit is contained in:
Pagan Gazzard 2014-10-01 18:37:35 +01:00 committed by Pablo Carranza Vélez
parent f43afd4a95
commit 5bb552f065
2 changed files with 12 additions and 1 deletions

View File

@ -40,7 +40,7 @@ knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
retryingBootstrap = ->
utils.mixpanelTrack('Device bootstrap')
bootstrap().catch (err) ->
utils.mixpanelTrack("Device bootstrap failed due to #{err?.message}, retrying in #{config.bootstrapRetryDelay}ms")
utils.mixpanelTrack('Device bootstrap failed, retrying', {error: err, delay: config.bootstrapRetryDelay})
Promise.delay(config.bootstrapRetryDelay)
.then(retryingBootstrap)
retryingBootstrap()

View File

@ -18,6 +18,17 @@ exports.mixpanelProperties = mixpanelProperties =
username: require('/boot/config.json').username
exports.mixpanelTrack = (event, properties = {}) ->
# Allow passing in an error directly and having it assigned to the error property.
if properties instanceof Error
properties = error: properties
# If the properties has an error argument that is an Error object then it treats it nicely,
# rather than letting it become `{}`
if properties.error instanceof Error
properties.error =
message: properties.error.message
stack: properties.error.stack
console.log('Event:', event, JSON.stringify(properties))
# Mutation is bad, and it should feel bad
properties = _.assign(_.cloneDeep(properties), mixpanelProperties)