feat: add error handling to player core functions

This commit is contained in:
2026-06-16 14:00:38 +02:00
committed by Milas Holsting
parent 3a1a2129d9
commit 2a8294c405
9 changed files with 45 additions and 22 deletions

View File

@@ -3,7 +3,8 @@ export type StorageLike = Pick<Storage, "getItem" | "setItem" | "removeItem">;
const getLocalStorage = (): StorageLike | null => {
try {
return window.localStorage;
} catch {
} catch (error) {
console.error("failed to access localstorage:", error);
return null;
}
};
@@ -14,7 +15,8 @@ export const safeLocalStorage = {
if (!storage) return null;
try {
return storage.getItem(key);
} catch {
} catch (error) {
console.error(`failed to get localstorage item '${key}':`, error);
return null;
}
},
@@ -23,8 +25,8 @@ export const safeLocalStorage = {
if (!storage) return;
try {
storage.setItem(key, value);
} catch {
// ignore
} catch (error) {
console.error(`failed to set localstorage item '${key}':`, error);
}
},
removeItem(key: string): void {
@@ -32,8 +34,8 @@ export const safeLocalStorage = {
if (!storage) return;
try {
storage.removeItem(key);
} catch {
// ignore
} catch (error) {
console.error(`failed to remove localstorage item '${key}':`, error);
}
},
};