Updated the default weather template and the weather logic to handle errors better
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -26,10 +26,19 @@ const WeatherWidget = () => {
|
|||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
try {
|
try {
|
||||||
if (typeof res === "string") {
|
if (typeof res !== "string") {
|
||||||
theWeather.value = JSON.parse(res);
|
return theWeather.value = DEFAULT_WEATHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parsedWeather = JSON.parse(res);
|
||||||
|
|
||||||
|
if (Object.keys(parsedWeather).includes("error")) {
|
||||||
|
return theWeather.value = DEFAULT_WEATHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return theWeather.value = parsedWeather;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
theWeather.value = DEFAULT_WEATHER;
|
||||||
console.error(`Failed to parse weather data: ${error}`);
|
console.error(`Failed to parse weather data: ${error}`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user