title: Angularjs interceptor not working
body: <p>I am trying to create a <code>$http</code> interceptor that looks like this:</p>
  
  <pre><code>.config(['$httpProvider',function($httpProvider){
  $httpProvider.interceptors.push(function($q,$window){
      return {
          'request':function(config){
              config.headers = config.headers || {};
              if($window.sessionStorage)
                  config.headers.Authorization = 'Bearer '+$window.sessionStorage.token;
          },
          'requestError':function(rejection)
          {
              $q.reject(rejection);
          },
          'response':function(response){
              return response || $q.when(response);
          },
          'responseError':function(response)
          {
              if(response!=null &amp;&amp; response.status == 401)
              {
                  delete $window.sessionStorage.token;
                  //make the user login again
              }
              return response || $q.when(response);   
          }       
      };
  });
  }])
  </code></pre>
  
  <p>The interceptor fails with the error:</p>
  
  <pre><code> TypeError: Cannot read property 'headers' of undefined
  at serverRequest (angular.js:9366)
  at processQueue (angular.js:13248)
  at angular.js:13264
  at Scope.$eval (angular.js:14466)
  at Scope.$digest (angular.js:14282)
  at Scope.$apply (angular.js:14571)
  at bootstrapApply (angular.js:1455)
  at Object.invoke (angular.js:4203)
  at doBootstrap (angular.js:1453)
  at bootstrap (angular.js:1473)
  </code></pre>