File tree Expand file tree Collapse file tree 2 files changed +15
-13
lines changed Expand file tree Collapse file tree 2 files changed +15
-13
lines changed Original file line number Diff line number Diff line change 1
1
import AppStorage from 'util/appStorage' ;
2
2
3
- jest . unmock ( 'util/appStorage' ) ;
4
-
5
3
describe ( 'appStorage util' , ( ) => {
6
4
const key = 'test-data' ;
7
5
const settings = {
Original file line number Diff line number Diff line change @@ -81,19 +81,23 @@ export default class AppStorage {
81
81
82
82
// if there are any keys that are not in the cache
83
83
if ( keys . length ) {
84
- // call the API to get the missing data
85
- data = await fetchFromApi ( keys , data ) ;
84
+ try {
85
+ // call the API to get the missing data
86
+ data = await fetchFromApi ( keys , data ) ;
86
87
87
- // update the expiration date only if it has expired. this ensures
88
- // that data will remain in the cache for up to the timeout
89
- const expires =
90
- cached && cached . expires > Date . now ( )
91
- ? cached . expires
92
- : Date . now ( ) + CACHE_TIMEOUT ;
88
+ // update the expiration date only if it has expired. this ensures
89
+ // that data will remain in the cache for up to the timeout
90
+ const expires =
91
+ cached && cached . expires > Date . now ( )
92
+ ? cached . expires
93
+ : Date . now ( ) + CACHE_TIMEOUT ;
93
94
94
- // update localStorage with the new data
95
- this . set ( cacheKey , { expires, data } ) ;
96
- log . info ( `updated cache with ${ keys . length } new ${ cacheKey } ` ) ;
95
+ // update localStorage with the new data
96
+ this . set ( cacheKey , { expires, data } ) ;
97
+ log . info ( `updated cache with ${ keys . length } new ${ cacheKey } ` ) ;
98
+ } catch ( error ) {
99
+ log . error ( `failed to fetch ${ cacheKey } from the API` , error . message ) ;
100
+ }
97
101
}
98
102
99
103
return data ;
You can’t perform that action at this time.
0 commit comments