diff --git a/src/controllers/user.js b/src/controllers/user.js index bceb3eb677..68cc7b9ccb 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -257,37 +257,44 @@ api.update = function(req, res, next) { }; api.cron = function(req, res, next) { - var user = res.locals.user, - progress = user.fns.cron(), - ranCron = user.isModified(), - quest = shared.content.quests[user.party.quest.key]; + try{ + var user = res.locals.user, + progress = user.fns.cron(), + ranCron = user.isModified(), + quest = shared.content.quests[user.party.quest.key]; + if (ranCron) res.locals.wasModified = true; + if (!ranCron) return next(null,user); + Group.tavernBoss(user,progress); + if (!quest) return user.save(next); - if (ranCron) res.locals.wasModified = true; - if (!ranCron) return next(null,user); - Group.tavernBoss(user,progress); - if (!quest) return user.save(next); - - // If user is on a quest, roll for boss & player, or handle collections - // FIXME this saves user, runs db updates, loads user. Is there a better way to handle this? - async.waterfall([ - function(cb){ - user.save(cb); // make sure to save the cron effects - }, - function(saved, count, cb){ - var type = quest.boss ? 'boss' : 'collect'; - Group[type+'Quest'](user,progress,cb); - }, - function(){ - var cb = arguments[arguments.length-1]; - // User has been updated in boss-grapple, reload - User.findById(user._id, cb); - } - ], function(err, saved) { - res.locals.user = saved; - next(err,saved); - user = progress = quest = null; - }); + // If user is on a quest, roll for boss & player, or handle collections + // FIXME this saves user, runs db updates, loads user. Is there a better way to handle this? + async.waterfall([ + function(cb){ + user.save(cb); // make sure to save the cron effects + }, + function(saved, count, cb){ + var type = quest.boss ? 'boss' : 'collect'; + Group[type+'Quest'](user,progress,cb); + }, + function(){ + var cb = arguments[arguments.length-1]; + // User has been updated in boss-grapple, reload + User.findById(user._id, cb); + } + ], function(err, saved) { + if(err) logging.loggly({error: e, stack: e.stack}) + res.locals.user = saved; + next(err,saved); + user = progress = quest = null; + }); + }catch(e){ + logging.loggly({ + error: e.stack || e + }); + throw e; + } }; diff --git a/src/logging.js b/src/logging.js index 476a76d41b..63ab51ade9 100644 --- a/src/logging.js +++ b/src/logging.js @@ -14,7 +14,8 @@ if (nconf.get('NODE_ENV') == 'production'){ // // Optional: Tag to send with EVERY log message // - tags: ['heroku'] + tags: ['heroku'], + json: true }); }