AngularJS http get 中的错误处理然后构造 [英] Error handling in AngularJS http get then construct
本文介绍了AngularJS http get 中的错误处理然后构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何处理 HTTP 错误,例如500、什么时候使用AngularJS的http get then"构造(promises)?
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.
推荐答案
您需要添加一个额外的参数:
You need to add an additional parameter:
$http.get(url).then(
function(response) {
console.log('get',response)
},
function(data) {
// Handle error here
})
这篇关于AngularJS http get 中的错误处理然后构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文