Error service updates

This commit is contained in:
Adina Țeudan 2021-08-27 20:26:06 +03:00
parent 7029f2942d
commit 45f90be54b

View File

@ -2,21 +2,20 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { HttpErrorResponse } from '@angular/common/http';
import { LoadingService } from '../loading';
export type Error = HttpErrorResponse | null;
import { map } from 'rxjs/operators';
@Injectable({ providedIn: 'root' })
export class ErrorService {
readonly hasError$: Observable<Error>;
private readonly _errorEvent$ = new BehaviorSubject<Error>(null);
readonly hasError$: Observable<boolean>;
private readonly _errorEvent$ = new BehaviorSubject<HttpErrorResponse | undefined>(undefined);
constructor(private readonly _loadingService: LoadingService) {
this.hasError$ = this._errorEvent$.asObservable();
this.hasError$ = this._errorEvent$.asObservable().pipe(map(e => !!e));
}
private _error: Error = null;
private _error?: HttpErrorResponse;
get error(): Error {
get error(): HttpErrorResponse | undefined {
return this._error;
}
@ -27,7 +26,7 @@ export class ErrorService {
}
clear(): void {
this._errorEvent$.next(null);
this._error = null;
this._errorEvent$.next(undefined);
this._error = undefined;
}
}