title: How to Redirect to Login if any http status Unauthorized in AngularJS
body: <p>I have developed an application using ASP.NET Web API, OAuth Authentication and AngularJS. Once the token invalid/expired its throwing <code>401 Unauthorized</code> status. in Angular I have also checked once the http status 401, I redirect it to login state. working perfectly. but I need to create a common/generic object in Angular for all http request, if any http request status 401, it'll automatically redirect to login, no need to check individually for all http request. please see my below code (errorCallback). </p>
  
  <p><strong>Angular Controller</strong></p>
  
  <pre><code> StudentServices.GetStudentProfileByPIN($scope.SearchPIN).then(function (response) {
          if (response.data != null) {
              $scope.PInAvailableMsg = "";
          }
          else {
          }
      }, function errorCallback(response) {
          if (response.status==401) {
              $window.location.href = "/#/login";
          }
      });
  </code></pre>