import { Injectable } from '@angular/core' ; import { HttpInterceptor , HttpRequest , HttpHandler , HttpEvent , HttpErrorResponse } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { tap } from 'rxjs/operators' ; import { LoginService } from 'app/core/login/login.service' ; @ Injectable ( ) export class AuthExpiredInterceptor implements HttpInterceptor { constructor ( private loginService ) { } intercept ( request , next ) { return next . handle ( request ) . pipe ( tap ( ( event ) => { } , ( err ) => { if ( err instanceof HttpErrorResponse ) { if ( err . status === 401 ) { this . loginService . logout ( ) ; } } } ) ) ; } }