[Library | Trunk]: Add Error interceptor

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59856 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2020-11-16 13:36:12 +00:00
parent a9a0d270cb
commit 6bc598a8ac
5 changed files with 110 additions and 70 deletions

View File

@ -55,6 +55,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
ngOnInit() {
this.updateLists();
this.userManagementService.getUserInfo().subscribe(user => {
if(user) {
if(!Session.isPortalAdministrator(user) && !Session.isCurator(this.type, user) && !Session.isManager(this.type, this.id, user)) {
this.router.navigate(['/user-info'], {
queryParams: {
@ -63,6 +64,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
}
});
}
}
});
}
@ -92,7 +94,6 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
if(error.status === 404) {
this.exists = false;
} else {
this.error = error.error.response;
}
this.loadActive = false;
}));

View File

@ -0,0 +1,38 @@
import {Injectable} from "@angular/core";
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {Observable, throwError} from "rxjs";
import {catchError} from "rxjs/operators";
import {Session} from "./login/utils/helper.class";
import {Router} from "@angular/router";
import {LoginErrorCodes} from "./login/utils/guardHelper.class";
import {properties} from "../../environments/environment";
@Injectable()
export class ErrorInterceptorService implements HttpInterceptor {
constructor(private router: Router) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(catchError(err => {
if ((err.status === 0 && this.isRegistryService(req)) || err.status === 401 || err.status === 403) {
this.logOut();
}
return throwError(err);
}));
}
isRegistryService(req: HttpRequest<any>):boolean {
return req.url.indexOf(properties.registryUrl) !== -1;
}
logOut() {
Session.removeUser();
this.router.navigate(['/user-info'], {
queryParams: {
'errorCode': LoginErrorCodes.NOT_LOGIN,
'redirectUrl': this.router.url
}
});
}
}

View File

@ -5,9 +5,7 @@ import { tap } from 'rxjs/operators';
import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser';
import { isPlatformServer } from '@angular/common';
@Injectable({
providedIn: 'root'
})
@Injectable()
export class HttpInterceptorService implements HttpInterceptor {
constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {}

View File

@ -1,3 +1,4 @@
<div>
<div [id]="(mainComponent)?'tm-main':''" [class]="(mainComponent)?'uk-section uk-padding-remove-top tm-middle':''">
<div uk-grid uk-grid>
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
@ -73,3 +74,4 @@
</div>
</div>
</div>
</div>

View File

@ -91,6 +91,7 @@ export class UserComponent {
paramsArray.push(queryParamsArray[i].split("=")[0]);
valuesArray.push(queryParamsArray[i].split("=")[1]);
}
console.debug('here');
this.router.navigate([route], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
} else {
this.router.navigate([route]);