Updated the default weather template and the weather logic to handle errors better

This commit is contained in:
Jas Singh
2024-07-27 13:07:25 -07:00
parent 588b08379d
commit 42ccd573be
2 changed files with 642 additions and 633 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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}`);
} }
}) })