From 635490d568f89c554c6a84ef5c19d8c243859bed Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Tue, 5 Oct 2021 18:49:16 -0700 Subject: [PATCH] don't throw local storage errors (#11752) --- web-console/src/utils/local-storage-keys.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/web-console/src/utils/local-storage-keys.tsx b/web-console/src/utils/local-storage-keys.tsx index 5d78bb38a0d..220a7095045 100644 --- a/web-console/src/utils/local-storage-keys.tsx +++ b/web-console/src/utils/local-storage-keys.tsx @@ -46,7 +46,11 @@ export type LocalStorageKeys = typeof LocalStorageKeys[keyof typeof LocalStorage export function localStorageSet(key: LocalStorageKeys, value: string): void { if (typeof localStorage === 'undefined') return; - localStorage.setItem(key, value); + try { + localStorage.setItem(key, value); + } catch (e) { + console.error('Issue setting local storage key', e); + } } export function localStorageSetJson(key: LocalStorageKeys, value: any): void { @@ -55,7 +59,12 @@ export function localStorageSetJson(key: LocalStorageKeys, value: any): void { export function localStorageGet(key: LocalStorageKeys): string | undefined { if (typeof localStorage === 'undefined') return; - return localStorage.getItem(key) || undefined; + try { + return localStorage.getItem(key) || undefined; + } catch (e) { + console.error('Issue getting local storage key', e); + return; + } } export function localStorageGetJson(key: LocalStorageKeys): any { @@ -70,5 +79,9 @@ export function localStorageGetJson(key: LocalStorageKeys): any { export function localStorageRemove(key: LocalStorageKeys): void { if (typeof localStorage === 'undefined') return; - localStorage.removeItem(key); + try { + localStorage.removeItem(key); + } catch (e) { + console.error('Issue removing local storage key', e); + } }