diff --git a/server/debug.log b/server/debug.log new file mode 100644 index 0000000..1e7ee80 --- /dev/null +++ b/server/debug.log @@ -0,0 +1 @@ +[1016/115344.136:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3) diff --git a/server/scripts/index.js b/server/scripts/index.js index 23750f2..493725c 100644 --- a/server/scripts/index.js +++ b/server/scripts/index.js @@ -53,7 +53,7 @@ const index = (() => { document.addEventListener('touchmove', e => { if (_FullScreenOverride) e.preventDefault(); }); $('#frmGetLatLng #txtAddress').devbridgeAutocomplete({ - serviceUrl: location.protocol + '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest', + serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest', deferRequestBy: 300, paramName: 'text', params: { @@ -492,7 +492,7 @@ const index = (() => { let data; try { - data = await utils.fetch.json(location.protocol + '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode', { + data = await utils.fetch.json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode', { data: { location: longitude + ',' + latitude, distance: 1000, // Find location up to 1 KM. diff --git a/server/scripts/modules/currentweather.js b/server/scripts/modules/currentweather.js index e74b4e3..44e821a 100644 --- a/server/scripts/modules/currentweather.js +++ b/server/scripts/modules/currentweather.js @@ -15,24 +15,37 @@ class CurrentWeather extends WeatherDisplay { // Load the observations let observations, station; - try { - // station observations - const observationsPromise = utils.fetch.json(`https://api.weather.gov/stations/${weatherParameters.stationId}/observations`,{ - cors: true, - data: { - limit: 2, - }, - }); - // station info - const stationPromise = utils.fetch.json(`https://api.weather.gov/stations/${weatherParameters.stationId}`); + // station number counter + let stationNum = 0; + while (!observations && stationNum < weatherParameters.stations.length) { + // get the station + station = weatherParameters.stations[stationNum]; + stationNum++; + try { + // station observations + observations = await utils.fetch.json(`${station.id}/observations`,{ + cors: true, + data: { + limit: 2, + }, + }); - // wait for the promises to resolve - [observations, station] = await Promise.all([observationsPromise, stationPromise]); + // test data quality + if (observations.features[0].properties.temperature.value === null || + observations.features[0].properties.windSpeed.value === null || + observations.features[0].properties.textDescription === null) { + observations = undefined; + throw new Error(`Unable to get observations: ${station.properties.stationIdentifier}, trying next station`); + } // TODO: add retry for further stations if observations are unavailable - } catch (e) { - console.error('Unable to get current observations'); - console.error(e); + } catch (e) { + console.error(e); + } + } + // test for data received + if (!observations) { + console.error('All current weather stations exhausted'); this.setStatus(STATUS.failed); return; } diff --git a/server/scripts/modules/latestobservations.js b/server/scripts/modules/latestobservations.js index c30767d..36b4f34 100644 --- a/server/scripts/modules/latestobservations.js +++ b/server/scripts/modules/latestobservations.js @@ -32,6 +32,10 @@ class LatestObservations extends WeatherDisplay { const allConditions = await Promise.all(regionalStations.map(async station => { try { const data = await utils.fetch.json(`https://api.weather.gov/stations/${station.id}/observations/latest`); + // test for temperature, weather and wind values present + if (data.properties.temperature.value === null || + data.properties.textDescription === '' || + data.properties.windSpeed.value === null) return; // format the return values return Object.assign({}, data.properties, { StationId: station.id,