summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts
diff options
context:
space:
mode:
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.ts34
1 files changed, 32 insertions, 2 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 50973763..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,9 +42,22 @@ import {
HttpHandler,
HttpRequest,
HttpHeaders,
+ HttpErrorResponse
} from '@angular/common/http';
-import { Observable } from 'rxjs';
+import { Observable, throwError} from 'rxjs';
import { v4 as uuid } from 'uuid';
+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>> {
const headerSettings: { [name: string]: string | string[]; } = {};
@@ -58,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