From 9b0f7daa2c1d637316fb156f24f7c0e94dd5372d Mon Sep 17 00:00:00 2001 From: "theis.gaedigk" Date: Sun, 3 Aug 2025 23:52:23 +0200 Subject: [PATCH] fix: update error response status and improve success message handling in weather fetching --- backend/routes/api.js | 2 +- frontend/src/components/WeatherForm.tsx | 3 --- frontend/src/utils/apiFunc.ts | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/routes/api.js b/backend/routes/api.js index 4e61d80..623c1f6 100644 --- a/backend/routes/api.js +++ b/backend/routes/api.js @@ -14,7 +14,7 @@ router.get("/fetchWeather", async (req, res) => { `https://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}` ); if (!locationResponse.ok) { - return res.status(404).json({ + return res.status(500).json({ error: "Error fetching location data. (Error: x32)", success: "false", data: null, diff --git a/frontend/src/components/WeatherForm.tsx b/frontend/src/components/WeatherForm.tsx index 3549099..c3b23d8 100644 --- a/frontend/src/components/WeatherForm.tsx +++ b/frontend/src/components/WeatherForm.tsx @@ -21,9 +21,6 @@ const WeatherCard: React.FC = () => { toast .promise(fetchWeather(city, getUnit()), { pending: "Fetching weather data...", - success: "Weather data loaded successfully!", - error: - "Failed to load weather data. Please check your entered city name. (Error: x4040)", }) .then(() => { if (localStorage.getItem("weather")) { diff --git a/frontend/src/utils/apiFunc.ts b/frontend/src/utils/apiFunc.ts index 6cde44b..566d403 100644 --- a/frontend/src/utils/apiFunc.ts +++ b/frontend/src/utils/apiFunc.ts @@ -21,6 +21,7 @@ export const fetchWeather = async (city: string, units: string) => { return; } localStorage.setItem("weather", JSON.stringify(responseData.data)); + myToast(responseData.success, "success"); return; } catch (error) { const errorMsg = JSON.stringify(error);