0

我正在使用承诺从某个 URL 访问一些数据并捕获我想使用 .catch 的错误。如果我错过了一些错误,我无论如何都可以在 .finally 中捕捉到,但我忽略了哪些错误?

 $http.get('/someUrl', config)
      .then(function(data) {      
    }).catch(function activateError(error) {
           if (!error.handled) {
           alert(error);
           }
    }).finally(function(){
    });
4

1 回答 1

0

$http 调用的响应返回一个带有status属性的对象。这是一个与您请求的响应代码相对应的数字。

因此,您可以尝试以这种方式处理您的错误:

$http.get(dataUrl)
    .success(function (data){
    })
    .error(function (error, status){
       if (!error.handled) {
           alert(error);
       }
       // handle error treatment with status code
  }); 

希望它有所帮助!

于 2017-11-23T11:10:41.177 回答