【发布时间】:2017-03-23 23:12:47
【问题描述】:
我正在向 nodejs 发送一个表单以进行身份验证。在以下函数中使用$http.get 并添加promise > .then。在生产中,这是否可以处理我可能从服务器获得的所有错误?我需要在这个函数中添加什么吗?
MyApp.controller("Login", function($scope, $http){
$scope.checkuser = function(user){
$http.get('/login', user).then(function(response){
if(response.data){
console.log(response.data);
//based on response.data create if else ..
} else {
console.log("nothing returned");
}
});
}
});
一如既往,非常感谢!
【问题讨论】:
-
它不处理不成功的响应 (200)。如果是 500、401 等,那么回调将不会触发。添加 catch 块。
标签: javascript angularjs node.js angular-promise angular-http