From: SANDHYA.JS Date: Wed, 6 Mar 2024 10:49:04 +0000 (+0530) Subject: Fix Bug 2340: Invalid error message in UI for some role permission X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=898b149c76d80255406030c7ad6e3b515314e0d0;p=osm%2FNG-UI.git Fix Bug 2340: Invalid error message in UI for some role permission - Added access denied lack of permission notification while setting vim accounts id get, ns_instances:opps:id:get and ns_instances:id:get as false. Change-Id: I220690baacb09231499f24ca2a8138c13f2d56d0 Signed-off-by: SANDHYA.JS --- diff --git a/src/app/vim-accounts/info-vim/InfoVimComponent.ts b/src/app/vim-accounts/info-vim/InfoVimComponent.ts index b89a1b9..02aea69 100644 --- a/src/app/vim-accounts/info-vim/InfoVimComponent.ts +++ b/src/app/vim-accounts/info-vim/InfoVimComponent.ts @@ -22,6 +22,8 @@ import { isNullOrUndefined } from 'util'; import { Component, Injector, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { TranslateService } from '@ngx-translate/core'; +import { NotifierService } from 'angular-notifier'; import { ERRORDATA } from 'CommonModel'; import { DataService } from 'DataService'; import { environment } from 'environment'; @@ -82,12 +84,20 @@ export class InfoVimComponent implements OnInit { /** Utilizes modal service for any modal operations @private */ private modalService: NgbModal; + /** Handle translate @public */ + private translateService: TranslateService; + + /** Notifier service to popup notification @private */ + private notifierService: NotifierService; + constructor(injector: Injector) { this.injector = injector; this.restService = this.injector.get(RestService); this.dataService = this.injector.get(DataService); this.activatedRoute = this.injector.get(ActivatedRoute); this.modalService = this.injector.get(NgbModal); + this.translateService = this.injector.get(TranslateService); + this.notifierService = this.injector.get(NotifierService); this.router = this.injector.get(Router); } @@ -141,10 +151,15 @@ export class InfoVimComponent implements OnInit { this.isLoadingResults = false; }, (error: ERRORDATA) => { this.isLoadingResults = false; - if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) { + if (error.error.status === HttpStatus.NOT_FOUND) { this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => { // Catch Navigation Error }); + } else if (error.error.status === HttpStatus.UNAUTHORIZED) { + this.notifierService.notify('error', this.translateService.instant('HTTPERROR.401')); + this.router.navigate(['/vim/details']).catch((): void => { + // Catch Navigation Error + }); } else { this.restService.handleError(error, 'get'); } diff --git a/src/services/RestService.ts b/src/services/RestService.ts index bea559a..d3d9ea0 100644 --- a/src/services/RestService.ts +++ b/src/services/RestService.ts @@ -141,8 +141,11 @@ export class RestService { this.notifierService.notify('error', err.error.detail !== undefined ? err.error.detail : this.translateService.instant('HTTPERROR.401')); } - this.activeModal.dismissAll(); + } else { + this.notifierService.notify('error', err?.error?.detail !== undefined ? + err?.error?.detail : this.translateService.instant('HTTPERROR.401')); } + this.activeModal.dismissAll(); } else if (err.error.status === HttpStatus.BAD_REQUEST) { this.notifierService.notify('error', err.error.detail !== undefined ? err.error.detail : this.translateService.instant('HTTPERROR.400')); @@ -177,7 +180,7 @@ export class RestService { }); return { url: apiURL, - httpOptions: {headers : apiHeaders} + httpOptions: { headers: apiHeaders } }; } }