We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent8522ec6 commit445abf5Copy full SHA for 445abf5
src/services/storage/index.ts
@@ -31,11 +31,9 @@ class Storage<T> {
31
}
32
publicget=async():Promise<T>=>{
33
constvalue:string|undefined=awaitthis.storage.get(this.key)
34
-if(value){
35
-returnJSON.parse(value)
36
-}elseif(SESSION_STORAGE_PATH){
+if(SESSION_STORAGE_PATH){
37
try{
38
-//optionally read from fileas a fallback tolocal storage
+//1. read from fileinstead oflocal storage if specified
39
constsessionFile=awaitreadFile(SESSION_STORAGE_PATH,`${this.filePath}.json`)
40
if(!sessionFile){
41
thrownewError('No session file found')
@@ -53,6 +51,15 @@ class Storage<T> {
53
51
console.warn(`Failed to read or parse session file:${SESSION_STORAGE_PATH}/${this.filePath}.json`)
54
52
55
+if(value){
+// 2. read from local storage
56
+try{
57
+returnJSON.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
63
returnthis.defaultValue
64
65
publicset=(value:T):void=>{