使用$ q.all()的AngularJS HTTP错误代码?

时间:2022-12-05 19:36:16

I have a bunch of http requests like this:

我有一堆像这样的http请求:

$q.all([$http({
    method: 'POST',
    url: urlOne,
    headers: {Authorization: "Token " + jqToken}
}), $http({
    method: 'POST',
    url: urlTwo,
    headers: {Authorization: "Token " + jqToken}
})])
    .then(function (results) {
        //do stuff
    });

However urlOne and urlTwo (and a bunch of others) may under some conditions return 403. In this case everything just freezes and then() function is never executed. How can I handle 403 responses? Thanks.

然而urlOne和urlTwo(以及其他一些)可能在某些条件下返回403.在这种情况下,一切都只是冻结,然后()函数永远不会执行。我如何处理403回复?谢谢。

1 个解决方案

#1


4  

It sounds like you need to handle errors.

听起来你需要处理错误。

$q.all([...])
  .then(
    function (results) {
      // Handle success
    }, function (err) {
      // Handle errors
    });

#1


4  

It sounds like you need to handle errors.

听起来你需要处理错误。

$q.all([...])
  .then(
    function (results) {
      // Handle success
    }, function (err) {
      // Handle errors
    });