From ece6ecaf61b9f624eedc93074a70c6178d02e42e Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Fri, 23 Apr 2021 10:34:54 +0200 Subject: [PATCH] bugfix: fix region w/o fullId infinite spinner --- src/ui/regionalFeatures/regionalFeature.service.ts | 4 ++-- .../singleFeatures/base/regionFeature.base.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ui/regionalFeatures/regionalFeature.service.ts b/src/ui/regionalFeatures/regionalFeature.service.ts index 07507f9eb..3a4f61c05 100644 --- a/src/ui/regionalFeatures/regionalFeature.service.ts +++ b/src/ui/regionalFeatures/regionalFeature.service.ts @@ -2,7 +2,7 @@ import { HttpClient } from "@angular/common/http"; import { Inject, Injectable, OnDestroy, Optional } from "@angular/core"; import { PureContantService } from "src/util"; import { getIdFromFullId, getRegionHemisphere, getStringIdsFromRegion, flattenReducer } from 'common/util' -import { forkJoin, from, Observable, of, Subject, Subscription } from "rxjs"; +import { forkJoin, from, Observable, of, Subject, Subscription, throwError } from "rxjs"; import { catchError, map, mapTo, shareReplay, switchMap } from "rxjs/operators"; import { IHasId } from "src/util/interfaces"; import { select, Store } from "@ngrx/store"; @@ -66,7 +66,7 @@ export class RegionalFeaturesService implements OnDestroy{ ) public getAllFeaturesByRegion(region: {['fullId']: string}){ - if (!region.fullId) throw new Error(`getAllFeaturesByRegion - region does not have fullId defined`) + if (!region.fullId) return throwError(`getAllFeaturesByRegion - region does not have fullId defined`) const regionFullIds = getStringIdsFromRegion(region) const hemisphereObj = (() => { const hemisphere = getRegionHemisphere(region) diff --git a/src/ui/regionalFeatures/singleFeatures/base/regionFeature.base.ts b/src/ui/regionalFeatures/singleFeatures/base/regionFeature.base.ts index 3df568395..6755dfca6 100644 --- a/src/ui/regionalFeatures/singleFeatures/base/regionFeature.base.ts +++ b/src/ui/regionalFeatures/singleFeatures/base/regionFeature.base.ts @@ -1,6 +1,6 @@ import { EventEmitter, Input, Output, SimpleChanges } from "@angular/core" import { BehaviorSubject, forkJoin, Observable, of } from "rxjs" -import { shareReplay, switchMap, tap } from "rxjs/operators" +import { catchError, shareReplay, switchMap, tap } from "rxjs/operators" import { IHasId } from "src/util/interfaces" import { IFeature, RegionalFeaturesService } from "../../regionalFeature.service" @@ -64,7 +64,11 @@ export class RegionFeatureBase{ ? this._regionalFeatureService.getAllFeaturesByRegion(changes.region.currentValue) : of([]) ).pipe( - + /** + * region may have no fullId defined + * in this case, just emit [] + */ + catchError(() => of([])) ).subscribe({ next: features => this.features = features, complete: () => this.isLoading = false -- GitLab