From faa79400d8b557ffb5e4c88c1630d08d6b1086f6 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Wed, 31 Jul 2024 16:07:13 +0100 Subject: [PATCH] and try and except --- src/national.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/national.py b/src/national.py index 45347d8..6ee28f0 100644 --- a/src/national.py +++ b/src/national.py @@ -71,12 +71,18 @@ def get_elexon_forecast( SolarForecastResponse: The forecast data wrapped in a SolarForecastResponse model. """ - response = forecast_generation_wind_and_solar_day_ahead_get( - _from=start_datetime_utc.isoformat(), - to=end_datetime_utc.isoformat(), - process_type=process_type, - format="json", - ) + try: + response = forecast_generation_wind_and_solar_day_ahead_get( + _from=start_datetime_utc.isoformat(), + to=end_datetime_utc.isoformat(), + process_type=process_type, + format="json", + ) + except Exception as e: + logger.error("Unhandled exception when collecting ELexon Data: %s", str(e)) + raise HTTPException( + status_code=500, detail="Internal Server Error when collecting Elexon Data" + ) if not response.data: return SolarForecastResponse(data=[])