-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter York
committed
Mar 28, 2024
1 parent
f541a3f
commit 8aae523
Showing
3 changed files
with
24 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
let storageQuotaExceeded = false; | ||
const storageQuotaErrorMessage = "Unable to save because the local storage quota has been exceeded: you may need to clear out your web browser's local storage for this app, or run in private mode before you can save again. Specific error here: "; | ||
|
||
export function setLocalStorageItem(name: string, content: string) { | ||
try { | ||
window.localStorage.setItem(name, content); | ||
} catch (error: any) { | ||
const isStorageQuotaError = error.stack && error.stack.includes("exceeded the quota.") && error.stack.includes("at setLocalStorageItem"); | ||
if (!storageQuotaExceeded && isStorageQuotaError) { | ||
window.alert(storageQuotaErrorMessage + error); | ||
storageQuotaExceeded = true; | ||
} else if(isStorageQuotaError) { | ||
console.log(`StorageQuotaExceeded again: ${error}`); | ||
} else { | ||
console.log(`Unexpected error when saving locally: ${error}`); | ||
} | ||
} | ||
}; | ||
let storageQuotaExceeded = false; | ||
const storageQuotaErrorMessage = | ||
"Unable to save because the local storage quota has been exceeded: you may need to clear out your web browser's local storage for this app, or run in private mode before you can save again. Specific error here: "; | ||
|
||
export function setLocalStorageItem(name: string, content: string) { | ||
try { | ||
window.localStorage.setItem(name, content); | ||
} catch (error: any) { | ||
const isStorageQuotaError = | ||
error.stack && | ||
error.stack.includes("exceeded the quota.") && | ||
error.stack.includes("at setLocalStorageItem"); | ||
if (!storageQuotaExceeded && isStorageQuotaError) { | ||
window.alert(storageQuotaErrorMessage + error); | ||
storageQuotaExceeded = true; | ||
} else if (isStorageQuotaError) { | ||
console.log(`StorageQuotaExceeded again: ${error}`); | ||
} else { | ||
console.log(`Unexpected error when saving locally: ${error}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters