From d6f712232942f41a47d652cfb6dabc9d6b1694c7 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Thu, 2 Nov 2023 16:36:25 +0200 Subject: [PATCH] RED-7558: backport generic errors. --- src/lib/error/server-error-interceptor.ts | 12 +++++++++--- src/lib/services/toaster.service.ts | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/error/server-error-interceptor.ts b/src/lib/error/server-error-interceptor.ts index 5619b4b..e70e8a1 100644 --- a/src/lib/error/server-error-interceptor.ts +++ b/src/lib/error/server-error-interceptor.ts @@ -1,9 +1,10 @@ import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpStatusCode } from '@angular/common/http'; -import { inject, Inject, Injectable, Optional } from '@angular/core'; -import { MonoTypeOperatorFunction, Observable, retry, throwError, timer } from 'rxjs'; +import { Inject, Injectable, Optional } from '@angular/core'; +import { finalize, MonoTypeOperatorFunction, Observable, retry, throwError, timer } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; import { MAX_RETRIES_ON_SERVER_ERROR, SERVER_ERROR_SKIP_PATHS } from './tokens'; import { ErrorService } from './error.service'; +import { LoadingService } from '../loading'; import { KeycloakService } from 'keycloak-angular'; import { IqserConfigService } from '../services'; @@ -49,6 +50,7 @@ export class ServerErrorInterceptor implements HttpInterceptor { private readonly _errorService: ErrorService, private readonly _keycloakService: KeycloakService, private readonly _configService: IqserConfigService, + private readonly _loadingService: LoadingService, @Optional() @Inject(MAX_RETRIES_ON_SERVER_ERROR) private readonly _maxRetries: number, @Optional() @Inject(SERVER_ERROR_SKIP_PATHS) private readonly _skippedPaths: string[], ) {} @@ -70,7 +72,11 @@ export class ServerErrorInterceptor implements HttpInterceptor { this._urlsWithError.add(req.url); } - return throwError(() => error); + return throwError(() => error).pipe( + finalize(() => { + this._loadingService.stop(); + }), + ); }), backoffOnServerError(this._maxRetries, this._skippedPaths), tap(() => { diff --git a/src/lib/services/toaster.service.ts b/src/lib/services/toaster.service.ts index 1662d69..372bee7 100644 --- a/src/lib/services/toaster.service.ts +++ b/src/lib/services/toaster.service.ts @@ -62,6 +62,10 @@ export class Toaster { return this._toastr.error(resultedMsg, options?.title, options); } + rawError(message: string, config?: Partial>) { + return this._toastr.error(message, undefined, config); + } + info(message: string, options?: Partial): ActiveToast { return this._showToastNotification(message, NotificationType.INFO, options); }