title: error handling with http interceptor not working in Angular
body: <p>I am working on Angular 8 </p>
  
  <p>I am trying to centralise error handling through Interceptor </p>
  
  <p><strong>My Interceptor code is running , but it is not returning any error</strong> </p>
  
  <pre><code>import {
      HttpEvent,
      HttpInterceptor,
      HttpHandler,
      HttpRequest,
      HttpResponse,
      HttpErrorResponse
     } from '@angular/common/http';
     import { Observable, throwError } from 'rxjs';
     import { retry, catchError } from 'rxjs/operators';
  import { RestService } from './restservice';
  import { Injectable } from '@angular/core';
  import { Router } from '@angular/router';
  
  
  @Injectable()
     export class HttpErrorInterceptor implements HttpInterceptor {
  
      constructor(private rest : RestService , private route : Router){}
  
  
  
      intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
        // console.log('jcsjdsjd');
        // console.error('xjxfjb');
        // console.log(request);
        // console.log(next);
        return next.handle(request).pipe(catchError(err =&gt; {
          console.log(err);
            if (err.status === 401) {
                // auto logout if 401 response returned from api
                // this.authenticationService.logout();
                location.reload(true);
            }
  
            const error = err.error.message || err.statusText;
            return throwError(error);
        }))
    }
  } 
  </code></pre>
  
  <p><strong>I have also defined interceptor in Providers of app.module.ts</strong></p>
  
  <pre><code>  providers: [RestService  , AuthGuard ,   commonRest    ,  {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpErrorInterceptor,
      multi: true
    }],
  </code></pre>
  
  <p>response that I am getting on request with error 403 is  : </p>
  
  <pre><code>    {
    "messagecode": 403,
    "message": "not valid token!"
  }
  </code></pre>