@@ -30,12 +30,9 @@ class Storage<T> {
3030this . defaultValue = defaultValue
3131}
3232public get = async ( ) :Promise < T > => {
33- const value :string | undefined = await this . storage . get ( this . key )
34- if ( value ) {
35- return JSON . parse ( value )
36- } else if ( SESSION_STORAGE_PATH ) {
33+ if ( SESSION_STORAGE_PATH ) {
3734try {
38- //optionally read from fileas a fallback to local storage
35+ //1. read from fileinstead of local storage if specified
3936const sessionFile = await readFile ( SESSION_STORAGE_PATH , `${ this . filePath } .json` )
4037if ( ! sessionFile ) {
4138throw new Error ( 'No session file found' )
@@ -53,6 +50,16 @@ class Storage<T> {
5350console . warn ( `Failed to read or parse session file:${ SESSION_STORAGE_PATH } /${ this . filePath } .json` )
5451}
5552}
53+ const value :string | undefined = await this . storage . get ( this . key )
54+ if ( value ) {
55+ // 2. read from local storage
56+ try {
57+ return JSON . parse ( value )
58+ } catch ( err ) {
59+ console . warn ( `Failed to parse session state from local storage:${ value } ` )
60+ }
61+ }
62+ // 3. fallback to the default
5663return this . defaultValue
5764}
5865public set = ( value :T ) :void => {