@@ -26,20 +26,42 @@ class TravelForecast extends WeatherDisplay {
26
26
if ( extra !== 0 ) this . timing . delay . push ( Math . round ( this . extra * this . cityHeight ) ) ;
27
27
// add the final 3 second delay
28
28
this . timing . delay . push ( 150 ) ;
29
+
30
+ // add previous data cache
31
+ this . previousData = [ ] ;
29
32
}
30
33
31
34
async getData ( weatherParameters , refresh ) {
32
35
// super checks for enabled
33
- if ( ! super . getData ( this . weatherParameters ) ) return ;
34
- const forecastPromises = TravelCities . map ( async ( city ) => {
36
+ if ( ! super . getData ( weatherParameters , refresh ) ) return ;
37
+
38
+ // clear stored data if not refresh
39
+ if ( ! refresh ) {
40
+ this . previousData = [ ] ;
41
+ }
42
+
43
+ const forecastPromises = TravelCities . map ( async ( city , index ) => {
35
44
try {
36
45
// get point then forecast
37
46
if ( ! city . point ) throw new Error ( 'No pre-loaded point' ) ;
38
- const forecast = await json ( `https://api.weather.gov/gridpoints/${ city . point . wfo } /${ city . point . x } ,${ city . point . y } /forecast` , {
39
- data : {
40
- units : settings . units . value ,
41
- } ,
42
- } ) ;
47
+ let forecast ;
48
+ try {
49
+ forecast = await json ( `https://api.weather.gov/gridpoints/${ city . point . wfo } /${ city . point . x } ,${ city . point . y } /forecast` , {
50
+ data : {
51
+ units : settings . units . value ,
52
+ } ,
53
+ } ) ;
54
+ // store for the next run
55
+ this . previousData [ index ] = forecast ;
56
+ } catch ( e ) {
57
+ // if there's previous data use it
58
+ if ( this . previousData ?. [ index ] ) {
59
+ forecast = this . previousData ?. [ index ] ;
60
+ } else {
61
+ // otherwise re-throw for the standard error handling
62
+ throw ( e ) ;
63
+ }
64
+ }
43
65
// determine today or tomorrow (shift periods by 1 if tomorrow)
44
66
const todayShift = forecast . properties . periods [ 0 ] . isDaytime ? 0 : 1 ;
45
67
// return a pared-down forecast
0 commit comments