I have a GET
request using the $http
service. However, the error handling is not executed.
This is the error I am getting, where I expect the console to print "You are not logged in" . (The API will respond with a 401 if the check fails)
Here's the Angular code
$http.get($rootScope.api + '/authentication/check-login').then(function(response) {
console.log('You are logged in');
}, function(response) {
console.log('You are not logged in');
});
What am I doing wrong?
Use .error
.
$http.get($rootScope.api + '/authentication/check-login')
.success(function(response) {
console.log('You are logged in');
})
.error(function(response) {
console.log('You are not logged in');
});
Try this--
$http.get($rootScope.api + '/authentication/check-login').success(function(data) {
console.log('You are logged in');
}).
error(function(response) {
console.log('You are not logged in');
});
Source doc for more info- https://docs.angularjs.org/api/ng/service/ $http
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.