From f3387cdce2cb72a8dfb10ec21cdf0d3222802a52 Mon Sep 17 00:00:00 2001 From: Carl Tessier Date: Sat, 21 Dec 2019 12:17:41 -0500 Subject: [PATCH] fix: gracefully ignore bad JSON in localstorage (#385) Don't crash (catch the exception) if the localstorage value does not contain valid JSON. --- src/utils/store.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/store.js b/src/utils/store.js index e0bf850..6d04d23 100644 --- a/src/utils/store.js +++ b/src/utils/store.js @@ -44,13 +44,13 @@ function get(key) { if (!isLocalStorageSupported) return try { var value = window.localStorage[`${NAMESPACE}.${key}`] + + if (value) { + return JSON.parse(value) + } } catch (e) { return } - - if (value) { - return JSON.parse(value) - } } }