Skip to content

Commit

Permalink
Wrap with try catch local storage accessing
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Nov 25, 2024
1 parent 373845b commit a3945d0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ export function get(k: string, def: any = null): any {
return null;
}

const key = `${PREFIX}_${k}`;
const val = localStorage.getItem(key);
return val ? JSON.parse(val) : def;
try {
const key = `${PREFIX}_${k}`;
const val = localStorage.getItem(key);
return val ? JSON.parse(val) : def;
} catch (e) {
return def;
}
}

export function set(k: string, v: any): void {
Expand Down

0 comments on commit a3945d0

Please sign in to comment.