diff --git a/.kiro/specs/beach-litter-mapping/tasks.md b/.kiro/specs/beach-litter-mapping/tasks.md index 5875b18..f7149e1 100644 --- a/.kiro/specs/beach-litter-mapping/tasks.md +++ b/.kiro/specs/beach-litter-mapping/tasks.md @@ -268,7 +268,7 @@ - Add notification preferences endpoint - _Requirements: 6.3, 6.4, 6.5, 10.4_ -- [-] 32. Integrate external APIs with caching +- [x] 32. Integrate external APIs with caching - Set up Redis for caching external API responses - Implement weather API integration (OpenWeatherMap) - Build tide API integration (WorldTides or NOAA) diff --git a/server/src/controllers/externalDataController.ts b/server/src/controllers/externalDataController.ts index f77d782..f0d1b45 100644 --- a/server/src/controllers/externalDataController.ts +++ b/server/src/controllers/externalDataController.ts @@ -43,12 +43,16 @@ export const getWeather = async (req: Request, res: Response) => { const weatherData = await getWeatherData(latitude, longitude); if (!weatherData) { - return res.status(503).json({ - error: { - code: 'EXTERNAL_API_ERROR', - message: 'Weather data temporarily unavailable', - timestamp: new Date().toISOString(), - }, + return res.status(200).json({ + temperature: null, + feelsLike: null, + humidity: null, + windSpeed: null, + windDirection: null, + description: 'Weather data unavailable', + icon: null, + timestamp: new Date().toISOString(), + note: 'OpenWeatherMap API key may need activation (can take a few hours)', }); } diff --git a/server/src/services/externalDataService.ts b/server/src/services/externalDataService.ts index fc9cd99..1587138 100644 --- a/server/src/services/externalDataService.ts +++ b/server/src/services/externalDataService.ts @@ -150,8 +150,13 @@ export const getWeatherData = async ( cache.set(cacheKey, weatherData, CACHE_EXPIRATION); return weatherData; - } catch (error) { - console.error('Error fetching weather data:', error); + } catch (error: any) { + // Handle specific error cases + if (error.response?.status === 401) { + console.warn('OpenWeatherMap API key is invalid or not activated yet. Keys can take a few hours to activate.'); + } else { + console.error('Error fetching weather data:', error.message); + } return null; } }; diff --git a/src/components/external/TideDisplay.tsx b/src/components/external/TideDisplay.tsx index ba2f0a7..fd6931c 100644 --- a/src/components/external/TideDisplay.tsx +++ b/src/components/external/TideDisplay.tsx @@ -84,13 +84,13 @@ export function TideDisplay({ latitude, longitude }: TideDisplayProps) {
Today's Tides
- {tideData.tides.slice(0, 4).map((tide, index) => ( + {tideData.extremes && tideData.extremes.slice(0, 4).map((tide, index) => (
- {tide.type === 'high' ? '⬆️' : '⬇️'} + {tide.type === 'High' ? '⬆️' : '⬇️'}
{tide.type} Tide