AngularJS http get中的错误处理然后构造 [英] Error handling in AngularJS http get then construct
本文介绍了AngularJS http get中的错误处理然后构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何处理HTTP错误,例如500,当使用AngularJS的"http get then"构造(承诺)时?
How can I handle an HTTP error, e.g. 500, when using the AngularJS "http get then" construct (promises)?
$http.get(url).then(
function(response) {
console.log('get',response)
}
)
问题是,对于任何非200 HTTP响应,都不会调用内部函数.
Problem is, for any non 200 HTTP response, the inner function is not called.
推荐答案
您需要添加其他参数:
$http.get(url).then(
function(response) {
console.log('get',response)
},
function(data) {
// Handle error here
})
这篇关于AngularJS http get中的错误处理然后构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文