summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts')
-rw-r--r--catalog-ui/src/app/ng2/http-interceptor/headers-interceptor.ts61
1 files changed, 61 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);
+ }
+ });
+ }
+}