Loading & error message services improvements

This commit is contained in:
Adina Țeudan 2021-10-14 14:02:45 +03:00
parent eb1204ad7e
commit bc35a23bb2
2 changed files with 10 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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 {