Skip to content

Commit

Permalink
Catch GeoJSON deserialization error
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Dec 3, 2023
1 parent d44e937 commit 4920ef5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/GeoJsonPages/Semantic/SubObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 ) );
}
Expand Down

0 comments on commit 4920ef5

Please sign in to comment.