title: Handling authentication errors in response
body: <p>From an Angular 4 app, I am calling REST services deployed on Tomcat. For Authentication, I am using Kerberos and it is working as expected for positive cases.</p>
  
  <p>I am facing an issue in handling errors in Angular when Kerberos authentication fails (let's say due to user not existing in AD).</p>
  
  <p>Here is my Angular code</p>
  
  <pre><code>this.restService.executeGET(url)
        .subscribe(
        (response: Response) =&gt; {
          let httpResponseStatus = response.status;
          console.log('httpResponseStatus: '+httpResponseStatus+', httpResponseAuthHeader: '+httpResponseAuthHeader)
          //Do something with the Response
        }
        ,
        (error) =&gt; {
          //Do something with the Error
          console.log('Authenication Failed' + error); 
  
        }
        )
  
   executeGET(url: string) {
      let reqHeaders = new Headers({ 'Content-Type': 'application/json' });
      reqHeaders.append('Accept', 'application/json');
      return this.http.get(url, { headers: reqHeaders });  
    }   
  </code></pre>
  
  <p>When Authentication succeeds and 200 is returned by the server, '(response: Response) => {}' gets executed as expected. When the response is 401 code with WWW-Authenticate: Negotiate header, neither the 'response' block nor the 'error' block gets executed and browser shows a 'Page can't be displayed' message.</p>
  
  <p>When I look at IE 11 Network tab, it shows that Response has been returned as 401/Negotiate but for some reason it is evading the angular code. </p>
  
  <p><a href="https://i.stack.imgur.com/Qr8fe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qr8fe.jpg" alt="Response Header 1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/QZc0u.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QZc0u.jpg" alt="Response Header 2"></a></p>
  
  <p>It seems that browser is showing the 'Page can't be displayed' message even before the Angular code get a chance to load.</p>
  
  <p>How can I ensure that some code block gets executed even when authentication fails, so that I can take appropriate action like redirecting user to login page. </p>