title: Additional layer to handle ajax calls better
body: <p>my system works like below;</p>
  
  <p>StatisticService</p>
  
  <p>There is only http calls in my service layer and collect data to use in controller.</p>
  
  <pre><code>angular.module('app').factory('StatisticService', ['$http', 'CONFIG', function ($http, CONFIG) {
  
  var urlBase = CONFIG.API_END_POINT + '/statistics';
  
  return  {
      getReport : function (data) {
          return $http.post( CONFIG.API_END_POINT + '/reports/mainReport', data);
      }
  }
  }]);
  </code></pre>
  
  <p>StatisticController</p>
  
  <pre><code>function init() {
          var mediaAccounts = MediaAccountService.findAll(),
              searchQueryList = SearchQueryService.getAll(),
              tags = TagService.getAllActiveTags(),
              dates = $scope.CacheService.getData('dateFormats');
  
          $q.all([mediaAccounts, searchQueryList, tags, dates])
              .then(function (result) {
                  $scope.mediaAccounts.push.apply($scope.mediaAccounts, result[0].data.resultData);
                  $scope.searchQueryList = result[1].data.resultData;
                  $scope.tags = result[2].data.resultData;
                  $scope.dateFilter = result[3];
                  $scope.dateFilter.selected = $scope.dateFilter[1];
              }).then(function () {
              $scope.refreshChart();
          });
      }
  </code></pre>
  
  <p>There is an init function for get methods and fill my controller with static data after that ive many post methods like;</p>
  
  <pre><code>function getReport(type) {
          return StatisticService.getReport({
              statisticType: type,
              dateFormat: $scope.dateFilter.selected,
              startDate: $scope.date.startDate.output('time'),
              endDate: $scope.date.endDate.output('time'),
              tagList: $scope.query.tagList,
              searchQueryList: $scope.query.searchQueryList,
              userIdList: $scope.query.userIdList
          });
      }
  </code></pre>
  
  <p>And this method checks success and error promises. Now i need to find a new approach to handle my calls against an unexcepted errors or if error occurs on front end it should not reach to rest services.</p>