From c3244477c0479dd174fa7d17c2a7e3621f26bd6d Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 13 Dec 2021 20:50:13 +0200 Subject: [PATCH] add 503, 504 & 509 as offline status codes --- src/lib/error/error.service.ts | 14 +++++++++++--- .../full-page-error/full-page-error.component.ts | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/error/error.service.ts b/src/lib/error/error.service.ts index dad801b..61175e8 100644 --- a/src/lib/error/error.service.ts +++ b/src/lib/error/error.service.ts @@ -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(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(() => { diff --git a/src/lib/error/full-page-error/full-page-error.component.ts b/src/lib/error/full-page-error/full-page-error.component.ts index 7ad5849..4450101 100644 --- a/src/lib/error/full-page-error/full-page-error.component.ts +++ b/src/lib/error/full-page-error/full-page-error.component.ts @@ -27,7 +27,7 @@ export class FullPageErrorComponent { readonly connectionStatus$: Observable; 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));