Added user info to db error

This commit is contained in:
Aman Kumar 2015-02-17 14:42:12 +05:30
parent 85a024546b
commit c76241be40
2 changed files with 9 additions and 0 deletions

View file

@ -42,6 +42,9 @@ module.exports.setup = (app) ->
return handler.patch(req, res, parts[1]) if req.route.method is 'patch' and parts[1]?
handler[req.route.method](req, res, parts[1..]...)
catch error
if req.user?
userInfo = req.user.getUserInfo()
log.info("UserId: #{userInfo.id} #{if req.user.isAnonymous() then '' else 'Email:'} #{userInfo.email}")
errorMessage = "Error trying db method #{req?.route?.method} route #{parts} from #{name}: #{error}"
log.error(errorMessage)
log.error(error)

View file

@ -41,6 +41,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