Can this be done?
for example, I have a logout service
logout: function() { var defer = $q.defer(); this.getCustomer().then(function(credentials) { $http.post(CONSTANT_VARS.BACKEND_URL + '/auth/logout', {username: credentials.username, customer: credentials.customer} ).success(function(data) { if (data.error) { defer.reject(data); } LocalForageFactory.remove(CONSTANT_VARS.LOCALFORAGE_CUSTOMER).then(function() { cleanLocalForage(); defer.resolve(data); }, function(err) { console.log(err); defer.reject(data); }); }).error(function(data) { cleanLocalForage(); defer.reject(data); }); }, function(err) { defer.reject(err); }); return defer.promise; },
and then I have a function in the controller that returns an error after the session ends. When the session expires, I need to log out and redirect it to the login path. So this is what I have so far:
$scope.removeSlip = function(slip) { BetSlipFactory.removeSlip(slip).then(function() { }, function(err) { console.log(err); AuthFactory.logout(); $location.path('/'); }); };
or should I do something similar with the promise of going into the promise of BetSlipFactory.removeSlip() ?
$scope.removeSlip = function(slip) { BetSlipFactory.removeSlip(slip).then(function() { }, function(err) { console.log(err); AuthFactory.logout().then(function() { $location.path('/'); }) }); };
is: what is correct in this case?
source share