AngularJS handles rejected resources in $ q.all

I am trying to handle errors with my resources and then handle the rejection of resources in $q.all() .

This is my code:

 var user = User.get({id: 1}, function() { // Success }, function(response) { // Error return $q.reject(response); }); var promiseList = [user]; $q.all(promiseList).then(function(){ // Success <-- this seems to run all the time }, function(response) { // Error <-- this never seems to run but I want it to }); 

When my user resource gets 404, an error callback processes it and returns $q.reject .

However, the success call in my $q.all is $q.all called, not my error . I would think because I reject my promise that the $q.all error $q.all will be triggered?

I appreciate that I have only 1 element in my promiseList , but should this not change if it is?

+11
javascript angularjs promise q
Feb 07 '14 at 11:11
source share
1 answer

According to Michael in the comments

I changed

 var promiseList = [user]; 

For this:

 var promiseList = [user.$promise]; 

And now $q.reject() matches $q.all() .

Amazing, thanks for the tip.

+12
Feb 07 '14 at 13:19
source share



All Articles