1

I'm using $q.all as below to test my simple code. Some how $q is taking very long time to process the second one in the promise array and my backend server is timing out. When I see Network tab in the browser, getAccountStatementList is giving me 200 status where as getInvoiceDetails shows pending for ever before server timeout. How do I resolve this?

var promises = [$http.get('getAccountStatementList'), $http.get('getInvoiceDetails')];

$q.all(promises).then(function(values){
    console.log("Values 0 "+values[0]); // value alpha
    console.log("Values 1 "+values[1]); // value beta
    complete();
});
3
  • This sounds like an issue with your back-end server since it is never completing the second request. It seems like you should be checking to see if the requests are properly formed from the client and if so, then examine the server code to see why it isn't completing the second request. Commented May 3, 2017 at 5:00
  • I was able to fetch the result if I run the second request directly in the browser, at the same time. Commented May 3, 2017 at 6:52
  • Also, I interchanged my promises array and now I get 200 status for getInvoiceDetails and getAccountStatementList shows pending Commented May 3, 2017 at 7:13

1 Answer 1

1

you can use the catch callback to catch the error.

$q.all(promises).then(function(values){
    console.log("Values 0 "+values[0]); // value alpha
    console.log("Values 1 "+values[1]); // value beta
    complete();
}).catch(function(error){
   console.log(error)
})

the downfall of this is even if one promise rejected, it will immediately come to the catch. not waiting for the rest of the batch.

Sign up to request clarification or add additional context in comments.

1 Comment

Tried this. but it's the same. Also, I interchanged my promises array and now I get 200 status for getInvoiceDetails and getAccountStatementList shows pending

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.