X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fservices%2FRestService.ts;h=d3d9ea0d26ec1edf81e3a1a4305c4fdc10044092;hb=60f0a51c47cca2eaff2e9cf55deacf0c90548f04;hp=464cc0f48dd8daea82590525855a06a35e0b0be3;hpb=218e881e8d5a5d01c41a255d7107d546d10c0329;p=osm%2FNG-UI.git diff --git a/src/services/RestService.ts b/src/services/RestService.ts index 464cc0f..d3d9ea0 100644 --- a/src/services/RestService.ts +++ b/src/services/RestService.ts @@ -20,6 +20,7 @@ * @file Provider for REST Service */ +import { isNullOrUndefined } from 'util'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @@ -28,7 +29,6 @@ import { NotifierService } from 'angular-notifier'; import { APIURLHEADER, ERRORDATA } from 'CommonModel'; import * as HttpStatus from 'http-status-codes'; import { Observable } from 'rxjs'; -import { isNullOrUndefined } from 'util'; /** * An Injectable is a class adorned with the @Injectable decorator function. @@ -127,12 +127,12 @@ export class RestService { return this.http.delete(getRequest.url, getRequest.httpOptions); } } + /** * Handle Error response based on the status. * @param error The error response reecieved from API call. * @param method The http request method. */ - // tslint:disable-next-line: cyclomatic-complexity public handleError(err: ERRORDATA, method?: string): void { if (err.error.status === HttpStatus.UNAUTHORIZED) { if (method !== 'get') { @@ -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 } }; } }