From 1e9f6da0c63b4fed166b1715c2420f9fce4296ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 18 Dec 2024 08:53:44 +0100 Subject: [PATCH] Better error handling On error return an error 500 Instead of continuing or raising the exception --- tilecloud_chain/internal_mapcache.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tilecloud_chain/internal_mapcache.py b/tilecloud_chain/internal_mapcache.py index 4775e3e5e..e5a0b5cc4 100644 --- a/tilecloud_chain/internal_mapcache.py +++ b/tilecloud_chain/internal_mapcache.py @@ -172,21 +172,22 @@ def read_from_cache(self, tile: Tile) -> Tile | None: with _GET_TILE.labels("redis").time(): return self._cache_store.get_one(tile) - def compute_tile(self, tile: Tile) -> None: + def compute_tile(self, tile: Tile) -> bool: """Create the tile.""" with _GET_TILE.labels("wms").time(): self.run(tile) if tile.error: _LOG.error("Tile %s %s in error: %s", tile.tilecoord, tile.formated_metadata, tile.error) - return + return False for tile_ in tile.metadata["tiles"].values(): # type: ignore if tile_.error: _LOG.error("Tile %s %s in error: %s", tile_.tilecoord, tile_.formated_metadata, tile_.error) - return + return False if tile_.data is None: _LOG.error("Tile %s %s in error: no data", tile_.tilecoord, tile_.formated_metadata) - return + return False self._cache_store.put_one(tile_) + return True @contextlib.contextmanager def lock(self, tile: Tile) -> Iterator[None]: @@ -241,7 +242,9 @@ def fetch( fetched_tile = generator.read_from_cache(tile) if fetched_tile is None: backend = "wms-generate" - generator.compute_tile(meta_tile) + success = generator.compute_tile(meta_tile) + if not success: + return server.error(config, 500, "Error while generate the tile, see logs for details") if meta_tile.error: _LOG.error( @@ -263,7 +266,7 @@ def fetch( tile.formated_metadata, ", ".join([str(e) for e in tiles]), ) - raise + return server.error(config, 500, "Error while getting the tile, see logs for details") response_headers = { "Expires": (