1.1.00
All checks were successful
Build and Release / build-and-release (push) Successful in 20m36s

This commit is contained in:
Bryan1029384756
2026-04-16 20:14:27 -05:00
parent 56a12fdf3e
commit 6813bb40dc
40 changed files with 2228 additions and 387 deletions

View File

@@ -4,12 +4,29 @@
*/
const PREFIX = 'discord-clone-settings:';
// Browsers spell the quota error in a few different ways across vendors.
// Normalizing here so callers can `if (err.isQuotaError)` regardless.
function isQuotaError(e) {
if (!e) return false;
const name = e.name || '';
const code = e.code;
return (
name === 'QuotaExceededError' ||
name === 'NS_ERROR_DOM_QUOTA_REACHED' ||
code === 22 ||
code === 1014
);
}
export default {
get(key) {
try {
const raw = localStorage.getItem(PREFIX + key);
return Promise.resolve(raw !== null ? JSON.parse(raw) : undefined);
} catch {
// Corrupted JSON or blocked storage access — return undefined so
// the caller falls back to defaults. Worth recovering silently
// here because a single bad key shouldn't take down the app.
return Promise.resolve(undefined);
}
},
@@ -18,8 +35,17 @@ export default {
try {
localStorage.setItem(PREFIX + key, JSON.stringify(value));
return Promise.resolve();
} catch {
return Promise.resolve();
} catch (e) {
if (isQuotaError(e)) {
// Reject so the caller can surface the quota error to the user —
// silently swallowing meant settings just "didn't save" with no
// warning. Decorate with a flag so callers can branch without
// sniffing error names themselves.
const err = new Error('Browser storage quota exceeded');
err.isQuotaError = true;
return Promise.reject(err);
}
return Promise.reject(e);
}
},
};