fix: increase autoClose duration for Toast notifications to improve user experience
refactor: enhance error handling in fetchWeather function with detailed console messages
This commit is contained in:
@@ -4,9 +4,11 @@ export const fetchWeather = async (city: string, apiKey: string) => {
|
||||
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||
).then((response) => {
|
||||
if (response.status === 401) {
|
||||
throw new Error("Network response was not ok");
|
||||
console.error("You are not authorized to access this resource. Please check your API key.");
|
||||
} else if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
console.error("Error fetching location data: ", response.statusText);
|
||||
}
|
||||
});
|
||||
const lat = location[0].lat;
|
||||
|
Reference in New Issue
Block a user