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: LoginService) {} intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe( tap( (event: HttpEvent) => {}, (err: any) => { if (err instanceof HttpErrorResponse) { if (err.status === 401) { this.loginService.logout(); } } } ) ); } }