title: Angular 5 / HttpInterceptor / Detect (cancelled) xhr
body: <p>In my angular app I'm seeing chrome (cancel) api calls that fire off too rapidly. I also have an HttpInterceptor that triggers a loading indicator with every HttpClient request after 500ms if the request has not completed. However, on the requests that get (cancelled) there does not seem to be any new event to subsequently hide my loading indicator.</p>
  
  <p>Is there a way to detect 'cancelled' requests in the HttpInterceptor so I can hide my loading indicator again?</p>
  
  <pre class="lang-js prettyprint-override"><code>  export class GlobalHttpInterceptor implements HttpInterceptor {
      constructor(
        private sessionService: SessionService,
        private loadingService: LoadingService
      ) { }
  
      intercept(
        req: HttpRequest&lt;any&gt;,
        next: HttpHandler
      ): Observable&lt;HttpEvent&lt;any&gt;&gt; {
  
        setTimeout(() =&gt; {
          if (showLoading) {
            this.loadingService.show();
          }
        }, 500);
        let showLoading = true;
  
        if (this.sessionService.headers.length &gt; 0) {
          for (const x of this.sessionService.headers) {
            req = req.clone({
              headers: req.headers.set(x.key, x.value)
            });
          }
        }
  
        return next.handle(req)
          .do(
            (response) =&gt; {
              if (response instanceof HttpResponse) {
                showLoading = false;
                this.loadingService.hide();
              }
            },
            (error) =&gt; {
              showLoading = false;
              this.loadingService.hide();
            }
          );
      }
    }
  </code></pre>