File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
src/app/modules/shared/interceptors Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ import {
44 HttpInterceptor ,
55 HttpHandler ,
66 HttpRequest ,
7+ HttpErrorResponse ,
78} from '@angular/common/http' ;
89import { Observable } from 'rxjs' ;
10+ import { tap } from 'rxjs/operators' ;
911
1012import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service' ;
1113import { environment } from './../../../../environments/environment' ;
1214import { EnvironmentType } from 'src/environments/enum' ;
1315import { LoginService } from '../../login/services/login.service' ;
16+ import { catchError } from 'rxjs/operators' ;
1417
1518@Injectable ( )
1619export class InjectTokenInterceptor implements HttpInterceptor {
@@ -25,7 +28,16 @@ export class InjectTokenInterceptor implements HttpInterceptor {
2528 headers : request . headers . set ( 'Authorization' ,
2629 'Bearer ' + token )
2730 } ) ;
28- return next . handle ( requestWithHeaders ) ;
31+ return next . handle ( requestWithHeaders )
32+ . pipe (
33+ tap ( ( ) => { } , ( err : any ) => {
34+ if ( err instanceof HttpErrorResponse ) {
35+ if ( err . status === 401 ) {
36+ this . loginService . logout ( ) ;
37+ }
38+ }
39+ } )
40+ ) ;
2941 } else {
3042 return next . handle ( request ) ;
3143 }
You can’t perform that action at this time.
0 commit comments