I feel like I may be doing something that Promises weren't designed to do, but here we go, this is what I'd like to do:
$http.get('/api/endpoint/PlanA.json').then(
function success( response ) {
if ( response.data.isAllGood ) {
$scope.myData = response.data;
}
else {
// TODO HERE! Call the failure function!
}
},
function failure() {
$http.get('/api/endpoint/PlanB.json').then(
function planBsuccess( response ) {
$scope.myData = response.data;
}
);
}
).then(function doOtherStuff() {});
This works as expected if, for example the PlanA
endpoint returns a 404 or 500... but if it succeeds, but has bad data (eg, isAllGood
is false), then I'd like it to get to the failure callback. Is there an easy way to do this?
I've tried calling $q.defer().reject
and returning that promise, however that just calls the failure callback for doOtherStuff
.