11import { HttpErrorResponse , HttpEvent , HttpHandler , HttpInterceptor , HttpRequest } from '@angular/common/http' ;
22import { Injectable } from '@angular/core' ;
3- import { NavigationError , Router } from '@angular/router' ;
3+ import { NavigationStart , Router } from '@angular/router' ;
44import { TranslateService } from '@ngx-translate/core' ;
55import { Store } from '@ngxs/store' ;
66import { ToastService } from 'app/shared/toast/ToastService' ;
@@ -10,13 +10,18 @@ import { catchError, filter, first } from 'rxjs/operators';
1010
1111@Injectable ( )
1212export class ErrorInterceptor implements HttpInterceptor {
13+ lastNavigatedURL : string = '' ;
1314
1415 constructor (
1516 private _toast : ToastService ,
1617 private _translate : TranslateService ,
1718 private _store : Store ,
1819 private _router : Router
19- ) { }
20+ ) {
21+ this . _router . events
22+ . pipe ( filter ( ( e ) : e is NavigationStart => e instanceof NavigationStart ) )
23+ . subscribe ( e => this . lastNavigatedURL = e . url ) ;
24+ }
2025
2126 intercept ( req : HttpRequest < any > , next : HttpHandler ) : Observable < HttpEvent < any > > {
2227 return next . handle ( req ) . pipe (
@@ -40,25 +45,18 @@ export class ErrorInterceptor implements HttpInterceptor {
4045 if ( e . error . message ) {
4146 // 194 is the error for "MFA required. See https://github.com/ovh/cds/blob/master/sdk/error.go#L205"
4247 if ( e . error . id === 194 && confirm ( `${ e . error . message } .\nDo you want to login using MFA ?` ) ) {
43- this . _router . events
44- . pipe (
45- filter ( ( e ) : e is NavigationError => e instanceof NavigationError ) ,
46- first ( )
47- )
48- . subscribe ( e => {
49- this . _store . dispatch ( new SignoutCurrentUser ( ) ) . subscribe ( ( ) => {
50- this . _router . navigate ( [ '/auth/ask-signin/corporate-sso' ] , {
51- queryParams : {
52- redirect_uri : e . url ,
53- require_mfa : true
54- }
55- } ) ;
56- } ) ;
48+ this . _store . dispatch ( new SignoutCurrentUser ( ) ) . subscribe ( ( ) => {
49+ this . _router . navigate ( [ '/auth/ask-signin/corporate-sso' ] , {
50+ queryParams : {
51+ redirect_uri : this . lastNavigatedURL ,
52+ require_mfa : true
53+ }
5754 } ) ;
58-
55+ } ) ;
5956 return observableThrowError ( e ) ;
6057 }
6158 this . _toast . errorHTTP ( e . status , e . error . message , e . error . from , e . error . request_id ) ;
59+ this . _router . navigate ( [ '/home' ] ) ;
6260 return observableThrowError ( e ) ;
6361 }
6462
0 commit comments