diff --git a/src/lib/loading/loading.service.ts b/src/lib/loading/loading.service.ts index efb767b..5492ee9 100644 --- a/src/lib/loading/loading.service.ts +++ b/src/lib/loading/loading.service.ts @@ -8,8 +8,13 @@ export class LoadingService { private readonly _loadingEvent$ = new BehaviorSubject(false); readonly isLoading$ = this._loadingEvent$.asObservable(); private _loadingStarted = 0; + private _timeout?: number; start(): void { + if (this._timeout) { + clearTimeout(this._timeout); + this._timeout = undefined; + } setTimeout(() => { this._loadingEvent$.next(true); this._loadingStarted = new Date().getTime(); @@ -37,6 +42,6 @@ export class LoadingService { } private _stopAfter(timeout: number): void { - setTimeout(() => this._stop(), timeout); + this._timeout = window.setTimeout(() => this._stop(), timeout); } } diff --git a/src/lib/services/error-message.service.ts b/src/lib/services/error-message.service.ts index cc186f1..eabd69e 100644 --- a/src/lib/services/error-message.service.ts +++ b/src/lib/services/error-message.service.ts @@ -8,8 +8,10 @@ import { HttpErrorResponse } from '@angular/common/http'; export class ErrorMessageService { constructor(private readonly _translateService: TranslateService) {} - getMessage(error: HttpErrorResponse, defaultMessage: string): string { - return (this._translateService.instant(defaultMessage) as string) + this._parseErrorResponse(error); + getMessage(error: HttpErrorResponse, defaultMessage?: string): string { + return defaultMessage + ? (this._translateService.instant(defaultMessage) as string) + this._parseErrorResponse(error) + : this._parseErrorResponse(error); } private _parseErrorResponse(err: HttpErrorResponse): string {