title: How to intercept every Ajax Request with Angular JS
body: <p>I need to intercept every Ajax Request to verify if the server responded with a <code>401 Unauthorized</code> because the session expired and redirect to the login page so the user don't think the app stopped working. I can do this the following way using JQuery:</p>
  
  <pre><code>$( document ).ajaxComplete(function( event, xhr, settings ) {
     if(xhr.errorCode == 401 || xhr.responseText === "unauthorized") {
      location.href = "/Login";
     }
  });
  </code></pre>
  
  <p>How can i do this with Angular JS?</p>