diff --git a/src/ui/regionalFeatures/regionalFeature.service.ts b/src/ui/regionalFeatures/regionalFeature.service.ts index 07507f9ebeb1f8812325d3ec9afdb23e032d48fc..3a4f61c055c98d7d7bdfa139525f36b5241a6929 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 3df5683951fafd247179e18d0be3a5f0d93862ee..6755dfca6a92819dd831118c13ef09b48f66c2c4 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