AngularJS - fail resilence on $q.all() AngularJS - fail resilence on $q.all() ajax ajax

AngularJS - fail resilence on $q.all()


This will work but also push the errors to the array.

function push(r) {    results.push(r);}$q.all([    this.getUserInfo(11).then(push).catch(push),    this.getUserConns().then(push).catch(push),    this.getUserCtxs().then(push).catch(push)]).then(function () {    console.log(results);})

You should also improve your understanding of promises, you never should use try-catch with promises - when using promises, you use the .catch() method (with everything else being implicitly a try). This works for normal errors as well as asynchronous errors.


If you want to totally ignore the errors:

function push(r) {    results.push(r);}function noop() {}$q.all([    this.getUserInfo(11).then(push).catch(noop),    this.getUserConns().then(push).catch(noop),    this.getUserCtxs().then(push).catch(noop)]).then(function () {    console.log(results);})


I think it's easier to do :

$q.all([ mypromise1.$promise.catch(angular.noop), mypromise2.$promise.catch(angular.noop), mypromise1.$promise.catch(angular.noop)]).then(function success(data) { //.....});


I'm not sure what you mean by resilient. What do you want to happen if one of the promises fails?

Your try-catch won't work because the promise will fail asynchronously.

You can however pass in an error handler as the second parameter to the then() call and do whatever you wish there.