From 03828b5a8698cf6b3a2ee5a3824cc335de63d986 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 26 Jun 2024 11:05:22 +0200 Subject: [PATCH] fix(mdview): catch OGC API error silently --- .../src/lib/state/mdview.facade.spec.ts | 62 +++++++++++-------- .../record/src/lib/state/mdview.facade.ts | 8 ++- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/libs/feature/record/src/lib/state/mdview.facade.spec.ts b/libs/feature/record/src/lib/state/mdview.facade.spec.ts index dbfe53f427..f0bba8948b 100644 --- a/libs/feature/record/src/lib/state/mdview.facade.spec.ts +++ b/libs/feature/record/src/lib/state/mdview.facade.spec.ts @@ -239,6 +239,30 @@ describe('MdViewFacade', () => { }) describe('geoDataLinksWithGeometry$', () => { + const links = [ + { + type: 'download', + url: new URL('http://my-org.net/download/2.geojson'), + mimeType: 'application/geo+json', + name: 'Direct download', + }, + { + type: 'service', + url: new URL('https://my-org.net/wfs'), + accessServiceProtocol: 'wfs', + name: 'my:featuretype', // FIXME: same as identifier otherwise it will be lost in iso... + description: 'This WFS service offers direct download capability', + identifierInService: 'my:featuretype', + }, + { + type: 'service', + url: new URL('https://my-org.net/ogc'), + accessServiceProtocol: 'ogcFeatures', + name: 'my:featuretype', + description: 'This OGC service offers direct download capability', + identifierInService: 'my:featuretype', + }, + ] beforeEach(() => { testScheduler = new TestScheduler((actual, expected) => { expect(actual).toEqual(expected) @@ -251,32 +275,6 @@ describe('MdViewFacade', () => { }) }) it('should return OGC links that have geometry', fakeAsync(() => { - const values = { - a: [ - { - type: 'download', - url: new URL('http://my-org.net/download/2.geojson'), - mimeType: 'application/geo+json', - name: 'Direct download', - }, - { - type: 'service', - url: new URL('https://my-org.net/wfs'), - accessServiceProtocol: 'wfs', - name: 'my:featuretype', // FIXME: same as identifier otherwise it will be lost in iso... - description: 'This WFS service offers direct download capability', - identifierInService: 'my:featuretype', - }, - { - type: 'service', - url: new URL('https://my-org.net/ogc'), - accessServiceProtocol: 'ogcFeatures', - name: 'my:featuretype', - description: 'This OGC service offers direct download capability', - identifierInService: 'my:featuretype', - }, - ], - } jest.spyOn(facade.dataService, 'getItemsFromOgcApi').mockResolvedValue({ id: '123', type: 'Feature', @@ -291,7 +289,17 @@ describe('MdViewFacade', () => { let result facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v)) tick() - expect(result).toEqual(values.a) + expect(result).toEqual(links) + })) + it('should return links that have geometry if OGC API does not respond', fakeAsync(() => { + jest + .spyOn(facade.dataService, 'getItemsFromOgcApi') + .mockRejectedValue(new Error('An error occurred')) + let result + facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v)) + tick() + const linksWithoutOgcApi = links.slice(0, -1) + expect(result).toEqual(linksWithoutOgcApi) })) it('should not return OGC links that do not have geometry', fakeAsync(() => { const values = { diff --git a/libs/feature/record/src/lib/state/mdview.facade.ts b/libs/feature/record/src/lib/state/mdview.facade.ts index c979cce049..605b623bf6 100644 --- a/libs/feature/record/src/lib/state/mdview.facade.ts +++ b/libs/feature/record/src/lib/state/mdview.facade.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core' import { select, Store } from '@ngrx/store' import { + catchError, defaultIfEmpty, filter, map, mergeMap, - scan, switchMap, toArray, } from 'rxjs/operators' @@ -119,7 +119,11 @@ export class MdViewFacade { ? link : null }), - defaultIfEmpty(null) + defaultIfEmpty(null), + catchError((e) => { + console.error(e) + return of(null) + }) ) } else { return of(link)