Improve the dahboard 6

This commit is contained in:
Urtzi Alfaro
2025-08-18 21:14:42 +02:00
parent 954f9a3c3f
commit d6fd53e461
3 changed files with 87 additions and 12 deletions

View File

@@ -22,7 +22,7 @@ class WeatherService:
self.database_manager = database_manager
async def get_current_weather(self, latitude: float, longitude: float) -> Optional[WeatherDataResponse]:
"""Get current weather for location"""
"""Get current weather for location with graceful failure handling"""
try:
logger.debug("Getting current weather", lat=latitude, lon=longitude)
weather_data = await self.aemet_client.get_current_weather(latitude, longitude)
@@ -31,12 +31,32 @@ class WeatherService:
logger.debug("Weather data received", source=weather_data.get('source'))
return WeatherDataResponse(**weather_data)
else:
logger.warning("No weather data received from AEMET client")
return None
logger.warning("No weather data received from AEMET client - providing service unavailable response")
# Return a response indicating service unavailable rather than None
return WeatherDataResponse(
date=datetime.utcnow().isoformat(),
temperature=None,
precipitation=None,
humidity=None,
wind_speed=None,
pressure=None,
description="Servicio meteorológico temporalmente no disponible",
source="unavailable"
)
except Exception as e:
logger.error("Failed to get current weather", error=str(e), lat=latitude, lon=longitude)
return None
# Return error response rather than None to prevent 404
return WeatherDataResponse(
date=datetime.utcnow().isoformat(),
temperature=None,
precipitation=None,
humidity=None,
wind_speed=None,
pressure=None,
description="Error al obtener datos meteorológicos",
source="error"
)
async def get_weather_forecast(self, latitude: float, longitude: float, days: int = 7) -> List[WeatherForecastResponse]:
"""Get weather forecast for location"""