I have a angular service that provides a login function in order to log in a user:
app.service('AuthSharedService', function($rootScope, $http, authService, UserSession) {
this.login = function(email, password, rememberMe) {
return $http.post('/login',
{
'email': email,
'password': password,
'rememberMe': rememberMe
})
.then(function(response){
console.log("success 1");
authService.loginConfirmed(response.data);
}).catch(function(response){
console.log("catch 1");
}).finally(function(response){
console.log("finally 1");
});
};
return this;
});
I also have a controller that is bound to a HTML login formular:
app.controller("loginController",
function ($scope, $rootScope, $window, $http, $routeParams, AuthSharedService){
var vm = this;
vm.email;
vm.password;
vm.rememberMe;
vm.login = function (){
AuthSharedService.login(vm.email, vm.password, vm.rememberMe)
.then(function(response){
console.log("success 2");
}).catch(function(response){
console.log("catch 2");
});
}
}
);
So far it is very basic.
But when I delete the database user table and then try to login, I get of course a internal error 500 on the REST server. But the console output of angular then is:
catch 1
success 2
But why? Can't I return a $http
in order to use the .then(function())
and the .catch(function())
twice?
thanks for any help :)
best regards