From 715069eabc0e9e442eb3d017d09862d699d14585 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 30 Jun 2023 14:39:48 +0300 Subject: [PATCH] Remove logs from reload. Add url variable in order to handle error from guards with the connect path. --- error-interceptor.service.ts | 16 +++++++++++++--- reload/reload.component.ts | 2 -- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/error-interceptor.service.ts b/error-interceptor.service.ts index 1ad66661..713949c3 100644 --- a/error-interceptor.service.ts +++ b/error-interceptor.service.ts @@ -3,15 +3,25 @@ import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/com import {Observable, throwError, TimeoutError} from "rxjs"; import {catchError} from "rxjs/operators"; import {Session} from "./login/utils/helper.class"; -import {Router} from "@angular/router"; +import {GuardsCheckEnd, GuardsCheckStart, Router} from "@angular/router"; import {LoginErrorCodes} from "./login/utils/guardHelper.class"; import {properties} from "../../environments/environment"; +import * as url from "url"; @Injectable() export class ErrorInterceptorService implements HttpInterceptor { private static UNAUTHORIZED_WHITELIST = [properties.userInfoUrl, properties.orcidAPIURL, properties.registryUrl? (properties.registryUrl + 'verification/'):null, properties.eoscDataTransferAPI].filter(value => !!value); + private url: string = null; + constructor(private router: Router) { + this.router.events.forEach(event => { + if(event instanceof GuardsCheckStart) { + this.url = event.url; + } else if(event instanceof GuardsCheckEnd) { + this.url = null; + } + }) } intercept(req: HttpRequest, next: HttpHandler): Observable> { @@ -42,7 +52,7 @@ export class ErrorInterceptorService implements HttpInterceptor { this.router.navigate(['/user-info'], { queryParams: { 'errorCode': LoginErrorCodes.NOT_LOGIN, - 'redirectUrl': this.router.url + 'redirectUrl': this.url?this.url:this.router.url } }); } @@ -51,7 +61,7 @@ export class ErrorInterceptorService implements HttpInterceptor { this.router.navigate(['/user-info'], { queryParams: { 'errorCode': LoginErrorCodes.NOT_AUTHORIZED, - 'redirectUrl': this.router.url + 'redirectUrl': this.url?this.url:this.router.url } }); } diff --git a/reload/reload.component.ts b/reload/reload.component.ts index 833b43ce..e86df79c 100644 --- a/reload/reload.component.ts +++ b/reload/reload.component.ts @@ -16,7 +16,6 @@ export class ReloadComponent { public ngOnInit() { let URL = Session.getReloadUrl(); - console.log(URL); if (URL && URL["path"] && URL["path"] != "") { let url: string = URL["path"]; let host = URL["host"]; @@ -24,7 +23,6 @@ export class ReloadComponent { if (host == (location.protocol + "//" + location.host)) { let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/"; url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url; - console.log(url); if (paramsObject) { Session.setReloadUrl("", "", "", ""); if(URL['fragment'] && URL['fragment'] !== '') {