title: Angularjs - handling 401's for entire app
body: <p>I have the following code in one of my Controllers to handle a 401 gracefully:</p>
  
  <pre><code>ChannelsService.query(function(response) {
      $scope.channels = response;
  }, function(error) {
      if (error.status == 401) {
          $state.go('login');
      }
  
  });
  </code></pre>
  
  <p>and my corresponding <code>service</code>:</p>
  
  <pre><code>myServices.factory('ChannelsService', function ($resource) {
      return $resource('/channels', {}, {
          query: { method: 'GET', isArray: true },
          create: { method: 'POST' }
      })
  });
  </code></pre>
  
  <p>I would like to know how to handle 401's globally so that I don't have to work this logic into every controller. Is it an interceptor that I need and if so could someone share some code?</p>
  
  <p>Thanks</p>