[英]Can we handle all the errors scenarios of http (4XX-5XX) using catch(error) in JS?
I am using a promise to access some data from some URL and to catch the errors i want to use .catch . 我正在使用一个承诺,以从一些URL访问一些数据,并捕获我想使用.catch的错误。 If i miss some error i can anyway catch in .finally but what all errors am i ignoring?
如果我错过了一些错误,无论如何我还是可以抓住。但我忽略的所有错误是什么?
$http.get('/someUrl', config)
.then(function(data) {
}).catch(function activateError(error) {
if (!error.handled) {
alert(error);
}
}).finally(function(){
});
The response of the $http call returns an object with a status
property. $ http调用的响应返回一个具有
status
属性的对象。 It's a number corresponding to the response code of your request. 该数字与您的请求的响应代码相对应。
So you could try handling your errors this way: 因此,您可以尝试通过以下方式处理错误:
$http.get(dataUrl)
.success(function (data){
})
.error(function (error, status){
if (!error.handled) {
alert(error);
}
// handle error treatment with status code
});
Hope it helped! 希望能有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.