Angular js http没有捕获promise错误

2 javascript angularjs

我不知道角度发生了什么,它没有捕捉到错误的反应,我在这里看到的问题没有答案.

我有一个简单的http请求,我得到400响应,我想在用户发生时向用户显示一条消息,问题是200的部分被执行了.

我试过两种方式:

 this.forgatPassword = function(data) {
      return $http.post('http://someaddress/ForgotPassword', data);  
  }

 $scope.forgatPassword = function() {
        AuthService.forgatPassword($scope.user).then(function(res) {
            $scope.message = true;             
        }, function(error) {
            console.log('rejected');
        });
    }

$scope.forgatPassword = function() {
        AuthService.forgatPassword($scope.user).then(function(res) {
            $scope.message = true;            
        }).catch( function(error) {
            console.log('rejected');
        });
    }
Run Code Online (Sandbox Code Playgroud)

Baz*_*nga 5

我有同样的问题,我发现在我的auth拦截器中我检查响应状态.如果响应状态是401我做了什么,但我忘了设置是否不返回承诺,所以拦截器没有转发拒绝.

因此,请确保您最终拥有此代码:

return $q.reject(rejection);
Run Code Online (Sandbox Code Playgroud)