one more error service update

This commit is contained in:
Dan Percic 2021-08-27 20:49:07 +03:00
parent 45f90be54b
commit c052a73f50
2 changed files with 4 additions and 13 deletions

View File

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

View File

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