From d0382e0de1deb841507a94d75924e6a364dddacb Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Thu, 8 Dec 2022 14:41:15 -0600 Subject: [PATCH] better error handlig of shared data --- server/scripts/modules/currentweather.mjs | 4 +++- server/scripts/modules/hourly-graph.mjs | 4 ++++ server/scripts/modules/hourly.mjs | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/scripts/modules/currentweather.mjs b/server/scripts/modules/currentweather.mjs index 14b9d09..f3f4cd8 100644 --- a/server/scripts/modules/currentweather.mjs +++ b/server/scripts/modules/currentweather.mjs @@ -55,7 +55,9 @@ class CurrentWeather extends WeatherDisplay { // test for data received if (!observations) { console.error('All current weather stations exhausted'); - this.setStatus(STATUS.failed); + if (this.enabled) this.setStatus(STATUS.failed); + // send failed to subscribers + this.getDataCallback(undefined); return; } // preload the icon diff --git a/server/scripts/modules/hourly-graph.mjs b/server/scripts/modules/hourly-graph.mjs index d9e8ba6..c26d993 100644 --- a/server/scripts/modules/hourly-graph.mjs +++ b/server/scripts/modules/hourly-graph.mjs @@ -28,6 +28,10 @@ class HourlyGraph extends WeatherDisplay { if (!super.getData()) return; const data = await getHourlyData(); + if (data === undefined) { + this.setStatus(STATUS.failed); + return; + } // get interesting data const temperature = data.map((d) => d.temperature); diff --git a/server/scripts/modules/hourly.mjs b/server/scripts/modules/hourly.mjs index 11af85e..0f0478d 100644 --- a/server/scripts/modules/hourly.mjs +++ b/server/scripts/modules/hourly.mjs @@ -37,12 +37,13 @@ class Hourly extends WeatherDisplay { } catch (e) { console.error('Get hourly forecast failed'); console.error(e.status, e.responseJSON); - this.setStatus(STATUS.failed); + if (this.enabled) this.setStatus(STATUS.failed); + // return undefined to other subscribers + this.getDataCallback(undefined); return; } this.data = await Hourly.parseForecast(forecast.properties); - this.getDataCallback(); if (!superResponse) return;