From c76241be4092ac827c6e6dfa8ad0dc00cadb8938 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 17 Feb 2015 14:42:12 +0530 Subject: [PATCH 1/2] Added user info to db error --- server/routes/db.coffee | 3 +++ server/users/User.coffee | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/server/routes/db.coffee b/server/routes/db.coffee index 8bcc8e231..fa281377a 100644 --- a/server/routes/db.coffee +++ b/server/routes/db.coffee @@ -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) diff --git a/server/users/User.coffee b/server/users/User.coffee index 61596c6f5..92445b4d0 100644 --- a/server/users/User.coffee +++ b/server/users/User.coffee @@ -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 From f7450c214cb911eb702ae974a39e1d5eb9fb80b5 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 17 Feb 2015 22:54:49 +0530 Subject: [PATCH 2/2] Added user info to db server error --- server/routes/db.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/routes/db.coffee b/server/routes/db.coffee index fa281377a..d34dc6869 100644 --- a/server/routes/db.coffee +++ b/server/routes/db.coffee @@ -42,10 +42,10 @@ 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 + errorMessage = "Error trying db method #{req?.route?.method} route #{parts} from #{name}: #{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}" + 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)