Merge pull request #2339 from amankr/server

Added user info to db error
This commit is contained in:
Nick Winter 2015-02-17 15:29:22 -08:00
commit d0f661508c
2 changed files with 9 additions and 0 deletions

View file

@ -43,6 +43,9 @@ module.exports.setup = (app) ->
handler[req.route.method](req, res, parts[1..]...)
catch error
errorMessage = "Error trying db method #{req?.route?.method} route #{parts} from #{name}: #{error}"
if req.user?
userInfo = req.user.getUserInfo()
errorMessage += "\n-- User Info Id: #{userInfo.id} #{if req.user.isAnonymous() then '' else 'Email:'} #{userInfo.email}"
log.error(errorMessage)
log.error(error)
log.error(error.stack)

View file

@ -45,6 +45,12 @@ UserSchema.methods.isAdmin = ->
UserSchema.methods.isAnonymous = ->
@get 'anonymous'
UserSchema.methods.getUserInfo = ->
info =
id : @get('_id')
email : if @get('anonymous') then 'Unregistered User' else @get('email')
return info
UserSchema.methods.trackActivity = (activityName, increment) ->
now = new Date()
increment ?= parseInt increment or 1