Suppose within my controller I have a few async methods and I use $q.all to wait for all of them to complete. How do I add error handling to one of the methods in case the data retrieval fails and assure $q.all gets called with the other data and appropriate error message for the one that failed?
app.controller('Ctrl', ['$scope','$q', function($scope, $q) {
var promises = [];
var controller_data;
promises.push(assyncMethod1());
promises.push(assyncMethod2());
$q.all(promises).then(function () {
....
})
function assyncMethod1() {
return $http.get("data.json").success( function(data) {
controller_data = data;
});
//on error?
}
function assyncMethod2() {
return $http.get("data2.json").success( function(data) {
...
});
//on error?
}
}]);
I know for single promises you would use:
//basic version
promise.then(fnSuccess)
.catch(fnFailure) //optional
.finally(fnAlways) //optional
But how would you do this for multiple functions?