title: Capture requests globally in angular 4 and stop if no internet
body: <p>I can get the connection status using <code>window.navigator.onLine</code> and using the HttpInterceptor as mentioned below i can get access to requests globally. But how do i cancel a request inside the HttpInterceptor? Or else is there a better way to handle this? </p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {
      HttpRequest,
      HttpHandler,
      HttpEvent,
      HttpInterceptor
  } from '@angular/common/http';
  import { Observable } from 'rxjs/Observable';
  @Injectable()
  export class InternetInterceptor implements HttpInterceptor {
      constructor() { }
  
      intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
          //check to see if there's internet
          if (!window.navigator.onLine) {
              return //cancel request
          }
          //else return the normal request
          return next.handle(request);
      }
  }
  </code></pre>