diff --git a/public/js/controllers/inventoryCtrl.js b/public/js/controllers/inventoryCtrl.js index b5c820d9a6..4c88f74588 100644 --- a/public/js/controllers/inventoryCtrl.js +++ b/public/js/controllers/inventoryCtrl.js @@ -75,15 +75,9 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL', } $scope.hatch = function(egg, potion){ - user.ops.hatch({query:{egg:egg.name, hatchingPotion:potion.name}}, function(err, req){ - // Bypassing the UserServices-injected callback so we can only show alert on success. It's safe, since this means - // UserServices callback will be 3rd param and never get called - if (err) return Notification.text(err); - User.log({op:'hatch', query:req.query}); - Notification.text("Your egg hatched! Visit your stable to equip your pet."); - $scope.selectedEgg = null; - $scope.selectedPotion = null; - }); + user.ops.hatch({query:{egg:egg.name, hatchingPotion:potion.name}}); + $scope.selectedEgg = null; + $scope.selectedPotion = null; } $scope.buy = function(type, item){ diff --git a/public/js/services/userServices.js b/public/js/services/userServices.js index 2c008b0369..d24990ae6a 100644 --- a/public/js/services/userServices.js +++ b/public/js/services/userServices.js @@ -74,8 +74,8 @@ angular.module('userServices', []). $rootScope.Shared.wrap(user); _.each(user.ops, function(op,k){ user.ops[k] = _.partialRight(op, function(err, req){ - //if (err) return Notification.text(err); // FIXME Circular dependency found: Notification <- User if (err) { + //Notification.text(err.code ? err.message : err); // FIXME Circular dependency found: Notification <- User alert(err.code ? err.message : err); // In the case of 200s, they're friendly alert messages like "You're pet has hatched!" - still send the op if ((err.code && err.code >= 400) || !err.code) return; diff --git a/src/controllers/user.js b/src/controllers/user.js index 23c5130e51..6006b15f70 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -460,17 +460,17 @@ api.cast = function(req, res) { _.each(shared.wrap({}).ops, function(op,k){ if (!api[k]) { api[k] = function(req, res, next) { - var user = res.locals.user; - async.series([ - function(cb){ user.ops[k](req, cb) }, - function(cb){ user.save(cb) }, - ], function(err){ + res.locals.user.ops[k](req,function(err){ + // If we want to send something other than 500, pass err as {code: 200, message: "Not enough GP"} if (err) { - // If we want to send something other than 500, pass err as {code: 200, message: "Not enough GP"} - if (err.code) return res.json(err.code, err.message); - return res.json(500,{err:err}); + if (!err.code) return res.json(500,{err:err}); + if (err.code >= 400) return res.json(err.code,{err:err.message}); + // In the case of 200s, they're friendly alert messages like "You're pet has hatched!" - still send the op } - return res.send(200); + res.locals.user.save(function(err){ + if (err) return res.json(500,{err:err}); + res.send(200); + }) }) } }