From 103bb1c88f3f15dfa4677c91ca98afded3af6f66 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 22 Feb 2016 16:01:17 +0000 Subject: [PATCH] add more error logging to group handler --- .../Subscription/SubscriptionGroupController.coffee | 13 +++++++++++-- .../Subscription/SubscriptionGroupHandler.coffee | 5 +++++ .../Subscription/SubscriptionUpdater.coffee | 9 +++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee index ff90023ff1..e7fdc4f3e3 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee @@ -15,6 +15,9 @@ module.exports = newEmail = req.body.email logger.log adminUserId:adminUserId, newEmail:newEmail, "adding user to group subscription" SubscriptionGroupHandler.addUserToGroup adminUserId, newEmail, (err, user)-> + if err? + logger.err err:err, newEmail:newEmail, adminUserId:adminUserId, "error adding user from group" + return res.sendStatus 500 result = user:user if err and err.limitReached @@ -25,14 +28,20 @@ module.exports = adminUserId = req.session.user._id userToRemove_id = req.params.user_id logger.log adminUserId:adminUserId, userToRemove_id:userToRemove_id, "removing user from group subscription" - SubscriptionGroupHandler.removeUserFromGroup adminUserId, userToRemove_id, -> + SubscriptionGroupHandler.removeUserFromGroup adminUserId, userToRemove_id, (err)-> + if err? + logger.err err:err, adminUserId:adminUserId, userToRemove_id:userToRemove_id, "error removing user from group" + return res.sendStatus 500 res.send() removeSelfFromGroup: (req, res)-> adminUserId = req.query.admin_user_id userToRemove_id = req.session.user._id logger.log adminUserId:adminUserId, userToRemove_id:userToRemove_id, "removing user from group subscription after self request" - SubscriptionGroupHandler.removeUserFromGroup adminUserId, userToRemove_id, -> + SubscriptionGroupHandler.removeUserFromGroup adminUserId, userToRemove_id, (err)-> + if err? + logger.err err:err, userToRemove_id:userToRemove_id, adminUserId:adminUserId, "error removing self from group" + return res.sendStatus 500 res.send() renderSubscriptionGroupAdminPage: (req, res)-> diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee index 41a3a0acb0..74d7a845cc 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionGroupHandler.coffee @@ -16,9 +16,14 @@ module.exports = SubscriptionGroupHandler = addUserToGroup: (subscription, newEmail, callback)-> UserCreator.getUserOrCreateHoldingAccount newEmail, (err, user)-> LimitationsManager.hasGroupMembersLimitReached subscription.admin_id, (err, limitReached)-> + if err? + return callback(err) if limitReached return callback(limitReached:limitReached) SubscriptionUpdater.addUserToGroup subscription.admin_id, user._id, (err)-> + if err? + logger.err err:err, "error adding user to group" + return callback(err) NotificationsBuilder.groupPlan(user, {subscription_id:subscription._id}).read() userViewModel = buildUserViewModel(user) callback(err, userViewModel) diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee index 7440657c7c..18f9058b67 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionUpdater.coffee @@ -32,6 +32,9 @@ module.exports = insertOperation = "$addToSet": {member_ids:user_id} Subscription.findAndModify searchOps, insertOperation, (err, subscription)-> + if err? + logger.err err:err, searchOps:searchOps, insertOperation:insertOperation, "error findy and modify add user to group" + return callback(err) UserFeaturesUpdater.updateFeatures user_id, subscription.planCode, callback removeUserFromGroup: (adminUser_id, user_id, callback)-> @@ -39,10 +42,12 @@ module.exports = admin_id: adminUser_id removeOperation = "$pull": {member_ids:user_id} - Subscription.update searchOps, removeOperation, -> + Subscription.update searchOps, removeOperation, (err)-> + if err? + logger.err err:err, searchOps:searchOps, removeOperation:removeOperation, "error removing user from group" + return callback(err) UserFeaturesUpdater.updateFeatures user_id, Settings.defaultPlanCode, callback - _createNewSubscription: (adminUser_id, callback)-> logger.log adminUser_id:adminUser_id, "creating new subscription" subscription = new Subscription(admin_id:adminUser_id)