Error service updates
This commit is contained in:
parent
7029f2942d
commit
45f90be54b
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user