fix: gracefully ignore bad JSON in localstorage (#385)

Don't crash (catch the exception) if the localstorage value does not contain valid JSON.
nolan/dark-mode-rebased
Carl Tessier 2019-12-21 12:17:41 -05:00 committed by Nolan Lawson
parent edcd64b101
commit f3387cdce2
1 changed files with 4 additions and 4 deletions

View File

@ -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)
}
}
}