gpt4 book ai didi

Javascript http 获取成功函数捕获错误响应

转载 作者:可可西里 更新时间:2023-11-01 17:06:29 24 4
gpt4 key购买 nike

我正在向返回 500 错误 响应的 url 发出 http 请求(这是预期的行为)。但这是在成功函数而不是错误函数中捕获的错误。

$http.get("myUrl")
.then(function (response) {
console.log(response);
}
.function (error) {
// Handle error here
});

请帮助理解这一点以及正确使用它的方法。

最佳答案

它应该是:

$http.get("myUrl")
.then(function (response) {
console.log(response);
}
,function (error) {
// Handle error here
});

或者

$http.get("myUrl")
.then(function (response) {
console.log(response);
})
.catch (function(error) {
// Handle error here
});

关于Javascript http 获取成功函数捕获错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39556198/

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