From 01d06f1c87607e636031763a90c60525c60d53a0 Mon Sep 17 00:00:00 2001 From: George Date: Fri, 23 Jun 2023 16:04:57 +0300 Subject: [PATCH] RED-6802, fixed the notification not showing up. --- src/lib/error/server-error-interceptor.ts | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/lib/error/server-error-interceptor.ts b/src/lib/error/server-error-interceptor.ts index 4f97871..98f4b46 100644 --- a/src/lib/error/server-error-interceptor.ts +++ b/src/lib/error/server-error-interceptor.ts @@ -1,4 +1,12 @@ -import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpStatusCode } from '@angular/common/http'; +import { + HttpErrorResponse, + HttpEvent, + HttpHandler, + HttpInterceptor, + HttpRequest, + HttpResponse, + HttpStatusCode, +} from '@angular/common/http'; import { Inject, Injectable, Optional } from '@angular/core'; import { MonoTypeOperatorFunction, Observable, retry, throwError, timer } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; @@ -57,7 +65,14 @@ export class ServerErrorInterceptor implements HttpInterceptor { intercept(req: HttpRequest, next: HttpHandler): Observable> { return next.handle(req).pipe( - catchError((error: HttpErrorResponse) => { + tap(event => { + if (event instanceof HttpResponse && this._urlsWithError.has(req.url)) { + this._errorService.setOnline(); + this._urlsWithError.delete(req.url); + } + }), + catchError((err: unknown) => { + const error = err as HttpErrorResponse; // token expired if (error.status === HttpStatusCode.Unauthorized) { this._keycloakStatusService.createLoginUrlAndExecute(); @@ -72,12 +87,6 @@ export class ServerErrorInterceptor implements HttpInterceptor { return throwError(() => error); }), backoffOnServerError(this._maxRetries, this._skippedPaths), - tap(() => { - if (this._urlsWithError.has(req.url)) { - this._errorService.setOnline(); - this._urlsWithError.delete(req.url); - } - }), ); } }