Is it OK to do that ?
for example, I have my log out 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() {
/*Removing LocalForage Items*/
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 a controller which returns an error once the session expires. When the session expires I need to logout the user and redirect him 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 like this with the logout promise into the BetSlipFactory.removeSlip()
promise ?
$scope.removeSlip = function(slip) {
BetSlipFactory.removeSlip(slip).then(function() {
}, function(err) {
console.log(err);
AuthFactory.logout().then(function() {
$location.path('/');
})
});
};
there is my question: what is the proper way in this case ?