one more error service update
This commit is contained in:
parent
45f90be54b
commit
c052a73f50
@ -2,31 +2,22 @@ import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { LoadingService } from '../loading';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ErrorService {
|
||||
readonly hasError$: Observable<boolean>;
|
||||
readonly error$: Observable<HttpErrorResponse | undefined>;
|
||||
private readonly _errorEvent$ = new BehaviorSubject<HttpErrorResponse | undefined>(undefined);
|
||||
|
||||
constructor(private readonly _loadingService: LoadingService) {
|
||||
this.hasError$ = this._errorEvent$.asObservable().pipe(map(e => !!e));
|
||||
}
|
||||
|
||||
private _error?: HttpErrorResponse;
|
||||
|
||||
get error(): HttpErrorResponse | undefined {
|
||||
return this._error;
|
||||
this.error$ = this._errorEvent$.asObservable();
|
||||
}
|
||||
|
||||
set(error: HttpErrorResponse): void {
|
||||
this._loadingService.stop();
|
||||
this._error = error;
|
||||
this._errorEvent$.next(error);
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this._errorEvent$.next(undefined);
|
||||
this._error = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
<ng-container *ngIf="errorService.hasError$ | async">
|
||||
<ng-container *ngIf="errorService.error$ | async as error">
|
||||
<section class="full-page-section"></section>
|
||||
<section class="full-page-content">
|
||||
<mat-icon svgIcon="iqser:error"></mat-icon>
|
||||
<div class="heading-l" translate="error.generic"></div>
|
||||
<p>{{ errorService.error.message }}</p>
|
||||
<p>{{ error.message }}</p>
|
||||
<iqser-icon-button
|
||||
(action)="reload()"
|
||||
[label]="'error.reload' | translate"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user