title: AngularJS http status 0 and redirection
body: <p>I have an application with Angularjs and Coldfusion.
  I have a form with some http queries for populating drop-down list.
  When the session server is out, I retrieve the status from the server, I display a dialog box (thanks to ngDialog) and I reload the page.(status 0 sent by the server because the server tries to reload an external authentication system before going on the main page of the application - not in the scope of this topic).</p>
  
  <p>Here <strong>my code</strong>:</p>
  
  <pre><code>app.controller('ctrlAddContacts', function ($scope, $route, ContactService, ngDialog, $timeout){
  
      ContactService.getCountry().success(function(countries){
          $scope.countries = countries;       
      }); 
  
      ContactService.loadCategory('undefined',0).success(function(categories, status, header, config){
          $scope.categories = categories;
          console.log("status:" + status);        
      })
      .error(function (data, status, header, config) {
          console.log("sessionExpired: " + sessionExpired);
          console.log("ERROR ");
          console.log("data: " + data);
          console.log("status:" + status);
          console.log("header: " + header);
          console.log("config: " + config);
                 if (status==0) {
                      alert("Your session expired - The page needs to be reloaded.\nPlease note that data enter in the form will be lost");        
  
                      // NGDIALOG BOX
  
                          var dialog = ngDialog.open({
                              template: '&lt;p&gt;Your session expired - The page needs to be reloaded.&lt;br /&gt;Please note that data enter in the form will be lost&lt;/p&gt;',
                              plain: true,
                              closeByDocument: false,
                              closeByEscape: false
                          });
                          setTimeout(function () {
                              dialog.close();
                              window.location = "http://myapp/index.cfm?#/add-contacts";      
                          }, 4000);
  
  
                  }                   
      }).finally(function() {
        console.log("finally finished repos");
      }); 
  
  });
  </code></pre>
  
  <p>It's working but I have to do that for each ajax HTTP request.</p>
  
  <p>Here I have to do the same for:</p>
  
  <pre><code>   ContactService.getCountry().success(function(countries){
          $scope.countries = countries;      
      }); 
  </code></pre>
  
  <p>Thus I wouldd like to simplify the code in order to avoid to repeat the line, could you tell me please if I can do that and how (directive or factory for instance)?</p>
  
  <p>Thanks</p>