title: How to send error data to server in Angular 4+ HttpInterceptor
body: <p>I've implemented HttpInterceptor for catching request errors in my Angular 5 application. My goal is to send another REST POST request to the server, which saves error log. It looks like this:</p>
  
  <pre><code>@Injectable()
  export class RestErrorHandler implements HttpInterceptor {
  
  private readonly ERROR_LOGGER_PATH: string = '/logger/errorEntry';
  
  constructor(private http: HttpClient, private restUtils: RestApiUtilsService) {}
  
  intercept(req: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
      return next.handle(req).catch((errorReponse: HttpErrorResponse) =&gt; {
          return this.handleRestError(errorReponse, req, next);
      });
  }
  
  public handleRestError(error: HttpErrorResponse, req: HttpRequest&lt;any&gt;, next: HttpHandler): ErrorObservable {
      let errorMessage = this.prepareErrorMessage(error);
      let entry = this.prepareEntry(errorMessage);
      this.http.post(this.restUtils.getUrl(this.ERROR_LOGGER_PATH), JSON.stringify(entry), this.restUtils.jsonResponseRequestOptions()).subscribe();
      return Observable.throw(error);
  }
  }
  
  export const ErrorInterceptorProvider = {
  provide: HTTP_INTERCEPTORS,
  useClass: RestErrorHandler,
  multi: true,
  };
  </code></pre>
  
  <p>Later on, I register ErrorInterceptorProvider as a provider in module.</p>
  
  <p>During start of the application, error occurs:</p>
  
  <pre><code>Cannot instantiate cyclic dependency! HttpClient ("[ERROR -&gt;]"): in NgModule AppModule in ./AppModule@-1:-1
  Cannot instantiate cyclic dependency! HttpClient ("[ERROR -&gt;]"): in NgModule AppModule in ./AppModule@-1:-1
  at NgModuleProviderAnalyzer.parse (compiler.js:19542)
  at NgModuleCompiler.compile (compiler.js:20131)
  at JitCompiler._compileModule (compiler.js:34430)
  at eval (compiler.js:34361)
  at Object.then (compiler.js:474)
  at JitCompiler._compileModuleAndComponents (compiler.js:34359)
  at JitCompiler.compileModuleAsync (compiler.js:34253)
  at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:239)
  at PlatformRef.bootstrapModule (core.js:5561)
  at eval (main.ts:10)
  </code></pre>
  
  <p>If I create another @Injectable() service calling rest API through HttpClient, which I inject inside RestErrorHandler there is no error. Why is it?</p>