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';
/** 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);
}
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');
}
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'));
});
return {
url: apiURL,
- httpOptions: {headers : apiHeaders}
+ httpOptions: { headers: apiHeaders }
};
}
}