import { Injectable } from '@angular/core' ; import { HttpInterceptor , HttpEvent , HttpRequest , HttpHandler , HttpErrorResponse , } from '@angular/common/http' ; import { Observable , throwError } from 'rxjs' ; import { Router } from '@angular/router' ; import { catchError } from 'rxjs/operators' ; import { DashboardRouter } from 'src/app/router/DashboardRouter' ; @ Injectable ( ) export class UnauthorizedInterceptor implements HttpInterceptor { constructor ( private router ) { } intercept ( req , next ) { return next . handle ( req ) . pipe ( catchError ( ( error ) => { if ( error && [ 401 , 403 ] . includes ( error . status ) ) { this . router . navigateByUrl ( DashboardRouter . redirectToList ( ) ) ; } return throwError ( error ) ; } ) ) ; } }