diff --git a/www/js/api_services.js b/www/js/api_services.js index 37590fd..c541c29 100644 --- a/www/js/api_services.js +++ b/www/js/api_services.js @@ -14,11 +14,16 @@ angular.module('starter.services', []) } Friends.all = function() { - return $http.get(apiServerUrl).then(function(response) { - console.log("Got some data"); - friends = response.data; - return new Friends(response.data); - }); + return $http.get(apiServerUrl) + .success(function(data) { + console.log("Success: Got some data"); + friends = data; + return new Friends(data); + }) + .error(function(data) { + console.log("Error: " + data); + throw new Error("Server returned an error"); + }); } Friends.getByMeetupId = function(meetupId) { diff --git a/www/js/controllers.js b/www/js/controllers.js index 408b27c..04830b0 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -31,7 +31,7 @@ angular.module('starter.controllers', ['ngStorage']) }); }) -.controller('FriendsCtrl', function($rootScope, $scope, $localStorage, $ionicLoading, Friends) { +.controller('FriendsCtrl', function($rootScope, $scope, $localStorage, $ionicLoading, Friends, $ionicViewService, $ionicPopup) { // Make the local storage available to the view $scope.$storage = $localStorage; @@ -47,13 +47,24 @@ angular.module('starter.controllers', ['ngStorage']) template: '' }); - var promise = Friends.all(); - promise.then(function(data) { - // Inject friends data into the root scope - $rootScope.friends = data; - // Hide the busy indicator - busy.hide(); - }); + var promise = Friends.all() + .then(function(data) { + // Inject friends data into the root scope + $rootScope.friends = data.data; + // Hide the busy indicator + busy.hide(); + }) + .catch(function(data){ + // Catch an error and go to the last view + $ionicViewService.getBackView().go(); + // Hide the busy indicator + busy.hide(); + // Display an error popup + $ionicPopup.alert({ + title: 'Error', + template: 'An error occurred while trying to retrieve the friends list.' + }); + }); }) .controller('FriendDetailCtrl', function($scope, $stateParams, $localStorage, Friends) { diff --git a/www/templates/tabs.html b/www/templates/tabs.html index e60f41b..6ec560a 100644 --- a/www/templates/tabs.html +++ b/www/templates/tabs.html @@ -5,20 +5,18 @@ --> - - - - - - - - + + + + + + - - + +