Skip to content

Commit

Permalink
Surround localStorage operations with try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Andr3wid committed Mar 26, 2024
1 parent f394161 commit e1d9ea7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ts/storageutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export namespace StorageUtils {
*/
export function setItem(key: string, data: string): void {
if (isLocalStorageAvailable()) {
window.localStorage.setItem(key, data);
try {
window.localStorage.setItem(key, data);
} catch (e) {
console.debug(`Failed to set storage item ${key}`, e);
}
}
}

Expand All @@ -29,7 +33,11 @@ export namespace StorageUtils {
*/
export function getItem(key: string): string | null {
if (isLocalStorageAvailable()) {
return window.localStorage.getItem(key);
try {
return window.localStorage.getItem(key);
} catch (e) {
console.debug(`Failed to get storage item ${key}`, e);
}
}

return null;
Expand Down

0 comments on commit e1d9ea7

Please sign in to comment.