import { Injectable, Injector, Inject } from '@angular/core'; import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'; import { throwError, of } from 'rxjs'; import { Observable } from 'rxjs'; import { catchError } from 'rxjs/operators'; @Injectable() export class EsbHttpInterceptor implements HttpInterceptor { constructor(@Inject('ESB_SESSION_TIMEOUT_HANDLER') public timeoutHandlerConfig: any) { console.log('ESB_SESSION_TIMEOUT_HANDLER'); console.log(this.timeoutHandlerConfig); } intercept(request: HttpRequest, next: HttpHandler): Observable> { /** * continues request execution */ return next.handle(request).pipe(catchError((error, caught) => { //intercept the respons error and displace it to the console if (this.timeoutHandlerConfig) { let errorText: string = error.error.text; if (error.status === 200) { if (errorText.indexOf('SAMLRequest') > 0) { console.log('EsbHttpInterceptor catchError:SAMLRequest'); // console.log('errorText:' + errorText); //console.log('error.status:' + error.status); if (this.timeoutHandlerConfig.showPopup) { let popupMsg = ` `; let div = document.createElement('div'); div.innerHTML = popupMsg; document.body.appendChild(div); } setTimeout(() => { window.location.href = this.timeoutHandlerConfig.url; }, this.timeoutHandlerConfig.countdown * 1000); } } } return of(caught); }) as any); } }