gpt4 book ai didi

angularjs - 当angularjs有400(错误请求)时如何捕获错误?

转载 作者:行者123 更新时间:2023-12-05 08:12:09 25 4
gpt4 key购买 nike

GET url 400(错误请求)或任何获取 url 错误。如何忽略错误?

$http.get(res.getQNUrl(domain, key, "exif"))
.success(function(data){
$scope.imageExifMap[key] = data
}).error(entry.onError)

例如:http://tratao-public.qiniudn.com/c851b00c127146997f017bb899bb9bb8.jpg?exif它会得到{"error":"no exif data"}

Chrome 获取错误:GET http://tratao-public.qiniudn.com/c851b00c127146997f017bb899bb9bb8.jpg?exif 400 (Bad Request)

最佳答案

var interceptor = ['$rootScope', '$q', "Base64", function (scope, $q, Base64) {
function success(response) {
return response;
}
function error(response) {
var status = response.status;
if (status == 400) {
window.location = "/account/login?redirectUrl=" + Base64.encode(document.URL);
return;
}
// otherwise
return $q.reject(response);
}
return function (promise) {
return promise.then(success, error);
}
}];

希望这对您有所帮助!

关于angularjs - 当angularjs有400(错误请求)时如何捕获错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24300143/

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