better error handling for api.weather.gov

This commit is contained in:
Matt Walsh 2020-09-09 15:23:19 -05:00
parent 9a09ccd1ea
commit eb321005d9
12 changed files with 39 additions and 69 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/twc3.html vendored
View file

@ -1 +1 @@
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><meta charset="utf-8"><link rel="preload" href="fonts/Star4000.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star 4 Radar.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Extended.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Large Compressed.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Large.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Small.woff" as="font" crossorigin="anonymous"><link rel="stylesheet" type="text/css" href="resources/twc3.min.css?_=2.3.3"><script type="text/javascript" src="resources/data.min.js"></script><script type="text/javascript" src="resources/ws.min.js?_=2.3.3"></script></head><body><div id="version" style="display:none">2.3.3</div><div id="container"></div></body></html>
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><meta charset="utf-8"><link rel="preload" href="fonts/Star4000.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star 4 Radar.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Extended.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Large Compressed.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Large.woff" as="font" crossorigin="anonymous"><link rel="preload" href="fonts/Star4000 Small.woff" as="font" crossorigin="anonymous"><link rel="stylesheet" type="text/css" href="resources/twc3.min.css?_=2.4.0"><script type="text/javascript" src="resources/data.min.js"></script><script type="text/javascript" src="resources/ws.min.js?_=2.4.0"></script></head><body><div id="version" style="display:none">2.4.0</div><div id="container"></div></body></html>

View file

@ -8016,13 +8016,6 @@ const _StationInfo = {
Latitude: 41.8666,
Longitude: -87.5833,
},
KIGQ: {
StationId: 'KIGQ',
City: 'Chicago/Lansing',
State: 'IL',
Latitude: 41.5333,
Longitude: -87.5333,
},
KZAU: {
StationId: 'KZAU',
City: 'Chicago/Artcc',
@ -8051,13 +8044,6 @@ const _StationInfo = {
Latitude: 39.8333,
Longitude: -88.85,
},
KDKB: {
StationId: 'KDKB',
City: 'De Kalb',
State: 'IL',
Latitude: 41.9333,
Longitude: -88.7,
},
KC73: {
StationId: 'KC73',
City: 'Dixon',
@ -8212,20 +8198,6 @@ const _StationInfo = {
Latitude: 41.45,
Longitude: -90.5166,
},
KC56: {
StationId: 'KC56',
City: 'Monee',
State: 'IL',
Latitude: 41.3833,
Longitude: -87.6833,
},
KC09: {
StationId: 'KC09',
City: 'Morris-Washburn',
State: 'IL',
Latitude: 41.4333,
Longitude: -88.4166,
},
KAJG: {
StationId: 'KAJG',
City: 'Mount Carmel',
@ -8317,13 +8289,6 @@ const _StationInfo = {
Latitude: 42.2,
Longitude: -89.1,
},
KRPJ: {
StationId: 'KRPJ',
City: 'Rochelle/Koritz',
State: 'IL',
Latitude: 41.8833,
Longitude: -89.0833,
},
KLOT: {
StationId: 'KLOT',
City: 'Romeoville/Chi',
@ -23777,13 +23742,6 @@ const _StationInfo = {
Latitude: 43.4166,
Longitude: -88.7,
},
KENW: {
StationId: 'KENW',
City: 'Kenosha',
State: 'WI',
Latitude: 42.6,
Longitude: -87.9333,
},
KLSE: {
StationId: 'KLSE',
City: 'La Crosse',
@ -24085,13 +24043,6 @@ const _StationInfo = {
Latitude: 43.1666,
Longitude: -88.7166,
},
KUES: {
StationId: 'KUES',
City: 'Waukesha Cnty',
State: 'WI',
Latitude: 43.05,
Longitude: -88.25,
},
KPCZ: {
StationId: 'KPCZ',
City: 'Waupaca',

View file

@ -55,6 +55,7 @@ const icons = (() => {
return addPath('Cloudy.gif');
case 'fog':
case 'fog-n':
return addPath('Fog.gif');
case 'rain_sleet':
@ -124,7 +125,7 @@ const icons = (() => {
return addPath('Blowing Snow.gif');
default:
console.log(`Unable to locate regional icon for ${link} ${isNightTime}`);
console.log(`Unable to locate regional icon for ${conditionName} ${link} ${isNightTime}`);
return false;
}
};
@ -245,7 +246,7 @@ const icons = (() => {
return addPath('Blowing-Snow.gif');
default:
console.log(`Unable to locate icon for ${link} ${isNightTime}`);
console.log(`Unable to locate icon for ${conditionName} ${link} ${isNightTime}`);
return false;
}
};

View file

@ -50,6 +50,12 @@ class LatestObservations extends WeatherDisplay {
// cut down to the maximum of 7
this.data = actualConditions.slice(0,this.MaximumRegionalStations);
// test for at least one station
if (this.data.length < 1) {
this.setStatus(STATUS.noData);
return;
}
this.drawCanvas();
}

View file

@ -19,6 +19,11 @@ class LocalForecast extends WeatherDisplay {
// get raw data
const rawData = await this.getRawData(weatherParameters);
// check for data
if (!rawData) {
this.setStatus(STATUS.failed);
return;
}
// parse raw data
const conditions = this.parseLocalForecast(rawData);
@ -78,7 +83,7 @@ class LocalForecast extends WeatherDisplay {
this.currentScreen = 0;
this.timing.totalScreens = this.screenTexts.length;
this.drawCanvas();
this.setStatus(STATUS.loaded);
}
// get the unformatted data (also used by extended forecast)
@ -124,11 +129,7 @@ class LocalForecast extends WeatherDisplay {
this.screenTexts[this.screenIndex].split('\n').forEach((text, index) => {
draw.text(this.context, 'Star4000', '24pt', '#FFFFFF', 75, 140+40*index, text, 2);
});
this.finishDraw();
this.setStatus(STATUS.loaded);
}
// format the forecast

View file

@ -16,22 +16,19 @@ class Radar extends WeatherDisplay {
{time: 1, si: 2},
{time: 1, si: 3},
{time: 1, si: 4},
{time: 1, si: 5},
{time: 4, si: 6},
{time: 4, si: 5},
{time: 1, si: 0},
{time: 1, si: 1},
{time: 1, si: 2},
{time: 1, si: 3},
{time: 1, si: 4},
{time: 1, si: 5},
{time: 4, si: 6},
{time: 4, si: 5},
{time: 1, si: 0},
{time: 1, si: 1},
{time: 1, si: 2},
{time: 1, si: 3},
{time: 1, si: 4},
{time: 1, si: 5},
{time: 12, si: 6},
{time: 12, si: 5},
];
// pre-load background image (returns promise)
@ -214,10 +211,12 @@ class Radar extends WeatherDisplay {
this.data = radarInfo.map(radar=>radar.canvas);
this.times = radarInfo.map(radar=>radar.time);
this.setStatus(STATUS.loaded);
}
async drawCanvas() {
super.drawCanvas();
if (this.screenIndex === -1) return;
this.context.drawImage(await this.backgroundImage, 0, 0);
const {DateTime} = luxon;
// Title
@ -244,7 +243,6 @@ class Radar extends WeatherDisplay {
draw.text(this.context, 'Star4000 Small', '24pt', '#ffffff', 438, 105, this.times[this.screenIndex].toLocaleString(DateTime.TIME_SIMPLE), 2, 'center');
this.finishDraw();
this.setStatus(STATUS.loaded);
}
// utility latitude/pixel conversions

View file

@ -115,6 +115,12 @@ class RegionalForecast extends WeatherDisplay {
// filter out any false (unavailable data)
const regionalData = regionalDataAll.filter(data => data);
// test for data present
if (regionalData.length === 0) {
this.setStatus(STATUS.noData);
return;
}
// return the weather data and offsets
this.data = {
regionalData,
@ -123,7 +129,6 @@ class RegionalForecast extends WeatherDisplay {
};
this.setStatus(STATUS.loaded);
this.drawCanvas();
}
buildForecast (forecast, city, cityXY) {

View file

@ -59,6 +59,14 @@ class TravelForecast extends WeatherDisplay {
// wait for all forecasts
const forecasts = await Promise.all(forecastPromises);
this.data = forecasts;
// test for some data available in at least one forecast
const hasData = this.data.reduce((acc,forecast) => acc || forecast.high, false);
if (!hasData) {
this.setStatus(STATUS.noData);
return;
}
this.drawCanvas(true);
}

View file

@ -1 +1 @@
module.exports = '2.3.3';
module.exports = '2.4.0';