all files / app/components/waitIndicator/ waitHttpInterceptor.config.js

100% Statements 14/14
50% Branches 1/2
100% Functions 6/6
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                          736×     475× 475×   453× 453×       439× 439×       14× 14× 14×            
/**
 * @ngdoc object
 * @name app.components.config:waitHttpInterceptor 
 * @description
 * Automatically display the wait indicator during HTTP requests
 */
 
(function () {
  'use strict';
 
  angular
    .module('app.components')
    .config(config);
  
  /** @ngInject */
  function config($httpProvider) {
    $httpProvider.interceptors.push(interceptor);
    
    /** @ngInject */
    function interceptor($q, waitingState) {
      var endWait;
      return {
        'request': function (config) {
          endWait = waitingState.beginWait();
          return config;
        },
 
        'response': function (response) {
            endWait();
          return response;
        },
 
        'responseError': function (rejection) {
          Eif (endWait)
            endWait();
          return $q.reject(rejection);
        }
      };
    }
  }
})();