From 671c1766ce8b14b0495bc6f46003d5432762cb83 Mon Sep 17 00:00:00 2001 From: Carl Tessier Date: Fri, 6 Dec 2019 21:48:09 -0500 Subject: [PATCH] fix: gracefully ignore bad JSON in localstorage 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 e0bf85046..6d04d23b2 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) - } } }