我有一个使用 $http
服务的 GET
请求。但是,错误处理并未执行。
这是我收到的错误,我希望控制台打印“您尚未登录”。 (如果检查失败,API 将响应 401)
这是 Angular 代码
$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');
});
我做错了什么?
最佳答案
使用.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');
});
关于javascript - $http.get 上的错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27602333/