gpt4 book ai didi

javascript - AngularJS中的错误处理 http get then construct

转载 作者:IT王子 更新时间:2023-10-29 02:52:15 24 4
gpt4 key购买 nike

如何处理 HTTP 错误,例如500,当使用 AngularJS“http get then”构造( promise )时?

$http.get(url).then(
function(response) {
console.log('get',response)
}
)

问题是,对于任何非 200 HTTP 响应,都不会调用内部函数。

最佳答案

您需要添加一个额外的参数:

$http.get(url).then(
function(response) {
console.log('get',response)
},
function(data) {
// Handle error here
})

关于javascript - AngularJS中的错误处理 http get then construct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17080146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com