X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Finterceptor.ts;h=b1b2aa5b9da24bfce9020d091dca13533e317090;hb=ad70d4114bbfc5dbf20fd1a8151095d89610c759;hp=a9253f8c6f1a68c1030dcd7c47e02e6c635a95cf;hpb=a3e5b2cc0eaf68e4f167cbf6cb39a6e154457678;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/interceptor.ts b/webapp-frontend/src/app/interceptor.ts index a9253f8..b1b2aa5 100644 --- a/webapp-frontend/src/app/interceptor.ts +++ b/webapp-frontend/src/app/interceptor.ts @@ -18,16 +18,27 @@ * ========================LICENSE_END=================================== */ -import { Injectable, Injector } from '@angular/core'; -import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http'; -import { Observable, of } from 'rxjs'; +import { Injectable } from '@angular/core'; +import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { catchError } from 'rxjs/operators'; +import { throwError } from 'rxjs'; +import { NotificationService } from './services/ui/notification.service'; @Injectable() export class HttpRequestInterceptor implements HttpInterceptor { - constructor(private injector: Injector) {} + constructor(private notificationService: NotificationService) {} - intercept(request: HttpRequest, next: HttpHandler): Observable> { + intercept(request: HttpRequest, next: HttpHandler): Observable> { console.log('Interceptor Invoked' + request.url); - return next.handle(request); + return next.handle(request).pipe( + catchError((error: HttpErrorResponse) => { + console.error("Error from error interceptor", error); + + // show dialog for error message + this.notificationService.error(error.message); + return throwError(error); + }) + ) as Observable>; } }