fix: handle invalid weather API key gracefully and fix TideDisplay crash
- Fix TideDisplay component crash (use extremes instead of tides) - Handle 401 weather API errors gracefully (return null data with note) - Update weather controller to return 200 with null values instead of 503 - Add helpful message about API key activation time - Fix tide type capitalization (High/Low instead of high/low)
This commit is contained in:
@@ -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)',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user