Skip to content

Commit

Permalink
fix(search): handle filter geometry issue
Browse files Browse the repository at this point in the history
ATM if the geometry is not valid, the search crashes as it's passer the ES query. This ensure the geometry is valid, and use null if not
  • Loading branch information
fgravin committed Nov 21, 2023
1 parent 7c1e2d7 commit 7636904
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libs/feature/search/src/lib/state/effects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject, Injectable, Optional } from '@angular/core'
import { Actions, createEffect, ofType } from '@ngrx/effects'
import { select, Store } from '@ngrx/store'
import { buffer, combineLatestWith, debounceTime, from, of } from 'rxjs'
import { buffer, combineLatestWith, debounceTime, from, of, tap } from 'rxjs'
import {
catchError,
map,
Expand Down Expand Up @@ -47,6 +47,7 @@ import {
AuthService,
FavoritesService,
} from '@geonetwork-ui/api/repository/gn4'
import { valid as validGeoJson } from 'geojson-validation'

@Injectable()
export class SearchEffects {
Expand Down Expand Up @@ -130,8 +131,17 @@ export class SearchEffects {
return of([state, favorites, null])
}
return this.filterGeometry$.pipe(
tap((geom) => {
const isValid = validGeoJson(geom)
if (!isValid) {
throw '\nFilter geometry is not a valid GeoJson'
}
}),
map((geom) => [state, favorites, geom]),
catchError(() => of([state, favorites, null])) // silently opt out of spatial filter if an error happens
catchError((e) => {
console.warn('The filter geometry cannot be used', e)
return of([state, favorites, null])
}) // silently opt out of spatial filter if an error happens
)
}),
switchMap(
Expand Down

0 comments on commit 7636904

Please sign in to comment.