fix: update error response status and improve success message handling in weather fetching
This commit is contained in:
@@ -14,7 +14,7 @@ router.get("/fetchWeather", async (req, res) => {
|
|||||||
`https://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
`https://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||||
);
|
);
|
||||||
if (!locationResponse.ok) {
|
if (!locationResponse.ok) {
|
||||||
return res.status(404).json({
|
return res.status(500).json({
|
||||||
error: "Error fetching location data. (Error: x32)",
|
error: "Error fetching location data. (Error: x32)",
|
||||||
success: "false",
|
success: "false",
|
||||||
data: null,
|
data: null,
|
||||||
|
@@ -21,9 +21,6 @@ const WeatherCard: React.FC = () => {
|
|||||||
toast
|
toast
|
||||||
.promise(fetchWeather(city, getUnit()), {
|
.promise(fetchWeather(city, getUnit()), {
|
||||||
pending: "Fetching weather data...",
|
pending: "Fetching weather data...",
|
||||||
success: "Weather data loaded successfully!",
|
|
||||||
error:
|
|
||||||
"Failed to load weather data. Please check your entered city name. (Error: x4040)",
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (localStorage.getItem("weather")) {
|
if (localStorage.getItem("weather")) {
|
||||||
|
@@ -21,6 +21,7 @@ export const fetchWeather = async (city: string, units: string) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.setItem("weather", JSON.stringify(responseData.data));
|
localStorage.setItem("weather", JSON.stringify(responseData.data));
|
||||||
|
myToast(responseData.success, "success");
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMsg = JSON.stringify(error);
|
const errorMsg = JSON.stringify(error);
|
||||||
|
Reference in New Issue
Block a user