diff options
author | ys9693 <ys9693@att.com> | 2020-01-19 13:50:02 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-01-22 12:33:31 +0000 |
commit | 16a9fce0e104a38371a9e5a567ec611ae3fc7f33 (patch) | |
tree | 03a2aff3060ddb5bc26a90115805a04becbaffc9 /catalog-ui/src/app/ng2/http-interceptor | |
parent | aa83a2da4f911c3ac89318b8e9e8403b072942e1 (diff) |
Catalog alignment
Issue-ID: SDC-2724
Signed-off-by: ys9693 <ys9693@att.com>
Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe
Diffstat (limited to 'catalog-ui/src/app/ng2/http-interceptor')
-rw-r--r-- | catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts | 61 | ||||
-rw-r--r-- | catalog-ui/src/app/ng2/http-interceptor/index.ts | 7 |
2 files changed, 68 insertions, 0 deletions
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<any>, next: HttpHandler): Observable<HttpEvent<any>> { + 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<any>) => { /* 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 }, +]; |