@@ -16,20 +16,29 @@ export default {
1616 } ,
1717 actions : {
1818 async getHazardInfosAsync ( { commit, rootState } ) {
19- if ( rootState . globalStore . online ) {
20- let response = await api . getDocuments ( ) ;
21- commit ( SET_LIST , response . data ) ;
22- await localForage . setItem ( CACHE_KEY , response . data ) ;
23- } else {
24- var data = await localForage . getItem ( CACHE_KEY )
25- if ( data ) {
26- console . log ( "Serving from cache" ) ;
27- commit ( SET_LIST , data ) ;
19+
20+ try {
21+ commit ( "setBusy" , null , { root : true } ) ;
22+ commit ( "setError" , "" , { root : true } ) ;
23+
24+ if ( rootState . globalStore . online ) {
25+ let response = await api . getAll ( ) ;
26+ commit ( SET_LIST , response . data ) ;
27+ await localForage . setItem ( CACHE_KEY , response . data ) ;
2828 } else {
29- console . log ( "Offline without data" ) ;
29+ var data = await localForage . getItem ( CACHE_KEY )
30+ if ( data ) {
31+ console . log ( "Serving from cache" ) ;
32+ commit ( SET_LIST , data ) ;
33+ } else {
34+ console . log ( "Offline without data" ) ;
35+ }
3036 }
31-
32- }
37+ } catch {
38+ commit ( "setError" , "Could not load harzard information." , { root : true } ) ;
39+ } finally {
40+ commit ( "clearBusy" , null , { root : true } ) ;
41+ }
3342 }
3443 }
3544} ;
0 commit comments