From 849ddf7ff95a1f8d4af30876cb8457ca0181667c Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Sun, 3 Dec 2023 21:13:51 +0100 Subject: [PATCH] Catch GeoJSON deserialization error (#760) --- src/GeoJsonPages/Semantic/SubObjectBuilder.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/GeoJsonPages/Semantic/SubObjectBuilder.php b/src/GeoJsonPages/Semantic/SubObjectBuilder.php index 9edfa14b..c36c07a7 100644 --- a/src/GeoJsonPages/Semantic/SubObjectBuilder.php +++ b/src/GeoJsonPages/Semantic/SubObjectBuilder.php @@ -4,10 +4,10 @@ namespace Maps\GeoJsonPages\Semantic; +use GeoJson\Exception\UnserializationException; use GeoJson\Feature\FeatureCollection; use GeoJson\GeoJson; use GeoJson\Geometry\Point; -use Title; class SubObjectBuilder { @@ -18,7 +18,14 @@ class SubObjectBuilder { */ public function getSubObjectsFromGeoJson( string $jsonString ) { $json = json_decode( $jsonString ); - $geoJson = GeoJson::jsonUnserialize( $json ); + + try { + $geoJson = GeoJson::jsonUnserialize( $json ); + } + catch ( UnserializationException ) { + // TODO: log warning + return []; + } return iterator_to_array( $this->featureCollectionToSubObjects( $geoJson ) ); }