@@ -3,44 +3,34 @@ use crate::templates::RenderCtx;
3
3
use wasm_bindgen:: JsValue ;
4
4
5
5
/// Freezes the app's state to IndexedDB to be accessed in future.
6
- // TODO Error handling
7
6
pub async fn hsr_freeze ( render_ctx : RenderCtx ) {
8
7
let frozen_state = render_ctx. freeze ( ) ;
9
8
// We use a custom name so we don't interfere with any state freezing the user's doing independently
10
9
let idb_store = match IdbFrozenStateStore :: new_with_name ( "perseus_hsr" ) . await {
11
10
Ok ( idb_store) => idb_store,
12
- Err ( _) => {
13
- return ;
14
- }
11
+ Err ( err) => return log ( & format ! ( "IndexedDB setup error: {}." , err) ) ,
15
12
} ;
16
13
match idb_store. set ( & frozen_state) . await {
17
14
Ok ( _) => log ( "State frozen." ) ,
18
- Err ( _) => {
19
- return ;
20
- }
15
+ Err ( err) => log ( & format ! ( "State freezing error: {}." , err) ) ,
21
16
} ;
22
17
}
23
18
24
19
/// Thaws a previous state frozen in development.
25
20
// This will be run at the beginning of every template function, which means it gets executed on the server as well, so we have to Wasm-gate this
26
21
#[ cfg( target_arch = "wasm32" ) ]
27
- // TODO Error handling
28
22
pub async fn hsr_thaw ( render_ctx : RenderCtx ) {
29
23
use super :: { PageThawPrefs , ThawPrefs } ;
30
24
31
25
let idb_store = match IdbFrozenStateStore :: new_with_name ( "perseus_hsr" ) . await {
32
26
Ok ( idb_store) => idb_store,
33
- Err ( _) => {
34
- return ;
35
- }
27
+ Err ( err) => return log ( & format ! ( "IndexedDB setup error: {}." , err) ) ,
36
28
} ;
37
29
let frozen_state = match idb_store. get ( ) . await {
38
30
Ok ( Some ( frozen_state) ) => frozen_state,
39
31
// If there's no frozen state available, we'll proceed as usual
40
32
Ok ( None ) => return ,
41
- Err ( _) => {
42
- return ;
43
- }
33
+ Err ( err) => return log ( & format ! ( "Frozen state acquisition error: {}." , err) ) ,
44
34
} ;
45
35
46
36
// This is designed to override everything to restore the app to its previous state, so we should override everything
@@ -61,9 +51,7 @@ pub async fn hsr_thaw(render_ctx: RenderCtx) {
61
51
// We don't want this old state to persist if the user manually reloads (they'd be greeted with state that's probably out-of-date)
62
52
match idb_store. clear ( ) . await {
63
53
Ok ( _) => ( ) ,
64
- Err ( _) => {
65
- return ;
66
- }
54
+ Err ( err) => log ( & format ! ( "Stale state clearing error: {}." , err) ) ,
67
55
}
68
56
}
69
57
0 commit comments