diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts index 5a5a41a8..1539877c 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts @@ -42,21 +42,27 @@ import { HttpHandler, HttpRequest, HttpHeaders, + HttpErrorResponse } from '@angular/common/http'; -import { Observable } from 'rxjs'; +import { Observable, throwError} from 'rxjs'; import { v4 as uuid } from 'uuid'; -declare const getWebJunctionXSRFToken: any; +import { catchError } from 'rxjs/internal/operators/catchError'; +import { environment } from '../../../environments/environment'; + +function nthIndex(str, pat, n) { + var L = str.length, i = -1; + while (n-- && i++ < L) { + i = str.indexOf(pat, i); + if (i < 0) break; + } + return i; +} + export class HeaderInterceptor implements HttpInterceptor { intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { - // Clone the request to add the new header - // HttpHeader object immutable - copy values - var XSRFToken = getWebJunctionXSRFToken(); - console.log('XSRFToken:', XSRFToken); const headerSettings: { [name: string]: string | string[]; } = {}; headerSettings['X-ECOMP-RequestID'] = uuid(); const requestType = req.params.get('requestType'); - if (XSRFToken.name && XSRFToken.value) - headerSettings['X-XSRF-TOKEN'] = XSRFToken.value; if(requestType!=null && requestType==='fileUpload'){ //headerSettings['Content-Type'] = 'multipart/form-data'; }else{ @@ -65,6 +71,23 @@ export class HeaderInterceptor implements HttpInterceptor { const newHeader = new HttpHeaders(headerSettings); const clonedRequest = req.clone({ headers: newHeader, withCredentials: true }); // Pass the cloned request instead of the original request to the next handle - return next.handle(clonedRequest); + //return next.handle(clonedRequest); + var url = ''; + return next.handle(clonedRequest).pipe( + catchError(error => { + if ( error instanceof HttpErrorResponse ) { + if ( error.status === 0 ) { // If 0(302) Redirect to Login Page + if(window.location.pathname.split('/').length > 3) { + var portNum = ( window.location.port === '' || window.location.port === '0' ) ? '' : ':'+ window.location.port; + url = window.location.protocol + "//" + window.location.hostname + portNum + window.location.pathname.substring(0, nthIndex(window.location.pathname, "/", 2) + 0) + '/login.htm'; + window.open( url, '_self' ); + } else { + window.open( environment.baseUrl + 'login.htm', '_self' ); + } + } + } + return throwError(error); + }) + ); } }
\ No newline at end of file |