title: HTTP interceptor getting status 0 on failed request using Angular 2,4,6,7,8,9 TypeScript
body: <p>I have following implementation of HTTP interceptors with <code>Angular ^4.3.6</code>.</p>
  
  <pre><code>import {Injectable} from "@angular/core";
  import {
    HttpInterceptor,
    HttpHandler,
    HttpRequest,
    HttpEvent,
    HttpResponse,
    HttpErrorResponse
  } from "@angular/common/http";
  import {Observable} from "rxjs/Observable";
  import "rxjs/add/operator/do";
  
  @Injectable()
  export class InterceptorService implements HttpInterceptor {
  
    intercept(
      req: HttpRequest&lt;any&gt;,
      next: HttpHandler
  ): Observable&lt;HttpEvent&lt;any&gt;&gt; {
      return next.handle(req).do(evt =&gt; {
        console.log(evt);//this logs the success message properly
        if (evt instanceof HttpResponse) {
          //Keep going
        }
      },err =&gt; {
      console.log(err);
      //this logs the error but don't have useful info in it.
      });
  
  }
  }
  </code></pre>
  
  <p>On the successful http call, I get following members of <code>evt</code> which are valid on the first console.log.</p>
  
  <pre><code>ok:true
  status:200
  statusText:"OK"
  type:4 
  </code></pre>
  
  <p>]</p>
  
  <p>But on failure I don't have proper status code from the <code>err</code> block on the second console.log but have following message in DEV console from ZONE.js</p>
  
  <blockquote>
    <p>zone.js:2263 OPTIONS <a href="http://localhost:7001/coreRobo/neuralProcess" rel="nofollow noreferrer">http://localhost:7001/coreRobo/neuralProcess</a> 404(Not Found)</p>
  </blockquote>
  
  <pre><code>name:"HttpErrorResponse"
  ok:false
  status:0
  statusText:"Unknown Error" 
  </code></pre>
  
  <p>I am not sure what I am missing here but I wanted that status to give me something valid like 404,403 or heck 500 when it clearly is that what is happening. </p>
  
  <p>I just wanted those values so that I can show proper message to the UI and help client not panic on failure. </p>
  
  <p>Any help is welcomed. Thanks in advance.</p>