From 3a2982c8ebb09cea53efc558d65c1ec304698997 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Fri, 13 Mar 2026 20:27:27 +0100 Subject: fix: handle exceptions during point transformation and initialize shape points --- src/Enmarcha.Backend/Services/ShapeTraversalService.cs | 17 ++++++++++++++++- src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Enmarcha.Backend/Services/ShapeTraversalService.cs b/src/Enmarcha.Backend/Services/ShapeTraversalService.cs index 1f77929..10de3e0 100644 --- a/src/Enmarcha.Backend/Services/ShapeTraversalService.cs +++ b/src/Enmarcha.Backend/Services/ShapeTraversalService.cs @@ -41,7 +41,22 @@ public class ShapeTraversalService foreach (var point in points) { - var transformed = inverseTransform.Transform(new[] { point.Longitude, point.Latitude }); + double[]? transformed = null; + try + { + transformed = inverseTransform.Transform(new[] { point.Longitude, point.Latitude }); + } + catch (Exception) + { + _logger.LogError("Exception while transforming point from {Lat},{Lon}", point.Latitude, point.Longitude); + continue; + } + + if (transformed is null) + { + _logger.LogError("Transformed point from {Lat},{Lon} is null", point.Latitude, point.Longitude); + continue; + } shape.Points.Add(new Epsg25829 { X = transformed[0], Y = transformed[1] }); } return shape; diff --git a/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs b/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs index bb6a251..298e2f4 100644 --- a/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs +++ b/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs @@ -46,5 +46,5 @@ public class Epsg25829 public class Shape { public string ShapeId { get; set; } - public List Points { get; set; } + public List Points { get; set; } = []; } -- cgit v1.3