I have the following service in which there is the function to fetch the data for all dashboards of my system.
.service('dashboardServices', function ($http, $q) {
return {
getData: getData
}
//definition of promises and their http requests urls
var promise01 = $http({method: 'GET', url: urlpromise01, cache: false});
var promise02 = $http({method: 'GET', url: urlpromise02, cache: false});
var promise03 = $http({method: 'GET', url: urlpromise03, cache: false});
function getData(){
var promises = [];
var promises = $q.all([promise01, promise02, promise03])
.then(function(data){
setDashboardData(data[0].data);
setDashboardData(data[1].data);
setDynamicDashboardData(data[2].data);
})
return promises;
}
})
I am calling this service in my controller in order to open a modal window with loading message while fetching the data from the server.
.controller('MainCtrl', function($state, $scope, $ionicModal, dashboardServices) {
$ionicModal.fromTemplateUrl('views/loading.html', {
scope: $scope,
backdropClickToClose: false,
hardwareBackButtonClose: true,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show().then(function() {
dashboardServices.getData().then(function() {
$scope.closeModal();
})
})
}
$scope.closeModal = function() {
$scope.modal.hide();
};
})
Now I want to have a mean to show some sort of message in case the requests failed. because right now when at least one of the request fails, the loading modal window will never get closed. but I can't add .error(function()... in my controller it will throw an error saying that .then().... .error() is not supported for $q.all
What would be a possible way to implement this exception handing?