title: Catch no network error in Angular HttpClient
body: <p><strong>How to catch a no network (no internet connection) error from Rxjs Observable using Angular HttpClient</strong></p>
  <p>RXJS Catch error code</p>
  <pre><code>  .catch((err: HttpErrorResponse) =&gt; {
  
      if (err.error instanceof Error) {
        // A client-side or network error occurred. Handle it accordingly.
        console.error('An error occurred:', err.error.message);
      } else {
        // The backend returned an unsuccessful response code.
        // The response body may contain clues as to what went wrong,
        console.error(`Backend returned code ${err.status}, body was: ${err.error}`);
      }
  
      // ...optionally return a default fallback value so app can continue (pick one)
      // which could be a default value
      // return Observable.of&lt;any&gt;({my: &quot;default value...&quot;});
      // or simply an empty observable
      return Observable.empty&lt;T&gt;();
    });
  </code></pre>
  <p><a href="https://stackoverflow.com/questions/46019771/catching-errors-in-angular-httpclient">Same angular error code</a></p>
  <p>I'm trying to catch errors when the user has no network and is trying to post off an API request. In the code above, it says that err.error instanceof Error would catch any network errors but it doesn't.</p>
  <p>Using both Ios and Android simulators, whenever there's no network, I would get a error code of 0 and message, Unknown Error. I can just check when error code 0, then return a no internet connection message but I can never be certain it's actually a network error.</p>
  <p>Is there any method to guarantee the error is a no internet connection issue?</p>
  <p>Sure I could check for a network before getting or posting api requests, but then all my pages with api requests need to continuously monitor for a network connection.</p>