add 503, 504 & 509 as offline status codes

This commit is contained in:
Dan Percic 2021-12-13 20:50:13 +02:00
parent b46bfd3fa6
commit c3244477c0
2 changed files with 12 additions and 4 deletions

View File

@ -5,13 +5,21 @@ import { LoadingService } from '../loading';
import { filter, mapTo } from 'rxjs/operators';
import { NavigationStart, Router } from '@angular/router';
const isBadGateway = (error?: HttpErrorResponse) => error?.status === HttpStatusCode.BadGateway;
const BANDWIDTH_LIMIT_EXCEEDED = 509 as const;
const OFFLINE_STATUSES = [
HttpStatusCode.BadGateway,
HttpStatusCode.ServiceUnavailable,
HttpStatusCode.GatewayTimeout,
BANDWIDTH_LIMIT_EXCEEDED,
] as const;
const isOffline = (error?: HttpErrorResponse) => !!error && OFFLINE_STATUSES.includes(error.status);
@Injectable({ providedIn: 'root' })
export class ErrorService {
readonly error$ = new BehaviorSubject<HttpErrorResponse | undefined>(undefined);
readonly badGatewayError$ = this.error$.pipe(filter(isBadGateway), mapTo(new Event('offline')));
readonly serverError$ = this.error$.pipe(filter(error => !isBadGateway(error)));
readonly offlineError$ = this.error$.pipe(filter(isOffline), mapTo(new Event('offline')));
readonly serverError$ = this.error$.pipe(filter(error => !isOffline(error)));
constructor(private readonly _loadingService: LoadingService, private readonly _router: Router) {
_router.events.pipe(filter(event => event instanceof NavigationStart)).subscribe(() => {

View File

@ -27,7 +27,7 @@ export class FullPageErrorComponent {
readonly connectionStatus$: Observable<string | undefined>;
constructor(readonly errorService: ErrorService) {
const offline$ = merge(fromEvent(window, 'offline'), this.errorService.badGatewayError$);
const offline$ = merge(fromEvent(window, 'offline'), this.errorService.offlineError$);
const online$ = fromEvent(window, 'online').pipe(shareLast());
const removeIndicator$ = online$.pipe(delay(3000), mapTo(undefined));