From 16a9fce0e104a38371a9e5a567ec611ae3fc7f33 Mon Sep 17 00:00:00 2001 From: ys9693 Date: Sun, 19 Jan 2020 13:50:02 +0200 Subject: Catalog alignment Issue-ID: SDC-2724 Signed-off-by: ys9693 Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe --- .../ng2/http-interceptor/headers-interceptor.ts | 61 ++++++++++++++++++++++ catalog-ui/src/app/ng2/http-interceptor/index.ts | 7 +++ 2 files changed, 68 insertions(+) create mode 100644 catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts create mode 100644 catalog-ui/src/app/ng2/http-interceptor/index.ts (limited to 'catalog-ui/src/app/ng2/http-interceptor') diff --git a/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts b/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts new file mode 100644 index 0000000000..00e2fd8fcd --- /dev/null +++ b/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts @@ -0,0 +1,61 @@ +import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; +import { Injectable, Injector } from '@angular/core'; +import { SdcUiComponents, SdcUiServices } from 'onap-ui-angular'; +import { ButtonType } from 'onap-ui-angular/dist/common'; +import { Observable } from 'rxjs/Observable'; +import { ServerErrorResponse } from '../../models/server-error-response'; +import { Cookie2Service } from '../services/cookie.service'; +import { HttpHelperService } from '../services/http-hepler.service'; +import { TranslateService } from '../shared/translator/translate.service'; + +@Injectable() +export class HeadersInterceptor implements HttpInterceptor { + + constructor(private injector: Injector, private cookieService: Cookie2Service, private httpHelperService: HttpHelperService) {} + + intercept(req: HttpRequest, next: HttpHandler): Observable> { + let authReq = req.clone({ headers: req.headers.set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId()) + .set('Content-Type', 'application/json; charset=UTF-8') + .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId()) + .set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId()) + }); + + const uuidValue = this.httpHelperService.getUuidValue(authReq.url); + if (uuidValue !== '') { + authReq = authReq.clone({ headers: authReq.headers.set(this.cookieService.getUserIdSuffix(), this.cookieService.getUserId())}); + } + return next.handle(authReq).do( + + (event: HttpEvent) => { /* Do Nothing */ }, + + (err: any) => { + if (err instanceof HttpErrorResponse) { + const errorResponse: ServerErrorResponse = new ServerErrorResponse(err); + const modalService = this.injector.get(SdcUiServices.ModalService); + const translateService = this.injector.get(TranslateService); + + const errorDetails = { + 'Error Code': errorResponse.messageId, + 'Status Code': errorResponse.status + }; + + if (errorResponse.ecompRequestId) { + errorDetails['Transaction ID'] = errorResponse.ecompRequestId; + } + + if (errorResponse.messageId === 'POL5005') { + // Session and Role expiration special handling + modalService.openWarningModal( + 'Warning', + translateService.translate('ERROR_MODAL_TEXT', errorResponse), + 'warn-modal', + [ ] ); + } else { + modalService.openErrorDetailModal('Error', errorResponse.message, 'error-modal', errorDetails); + } + + return Observable.throwError(err); + } + }); + } +} diff --git a/catalog-ui/src/app/ng2/http-interceptor/index.ts b/catalog-ui/src/app/ng2/http-interceptor/index.ts new file mode 100644 index 0000000000..57eb238890 --- /dev/null +++ b/catalog-ui/src/app/ng2/http-interceptor/index.ts @@ -0,0 +1,7 @@ +import { HTTP_INTERCEPTORS } from '@angular/common/http'; +import { HeadersInterceptor } from './headers-interceptor'; +import IStateService = angular.ui.IStateService; + +export const httpInterceptorProviders = [ + { provide: HTTP_INTERCEPTORS, useClass: HeadersInterceptor, multi: true }, +]; -- cgit 1.2.3-korg