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

Don't crash (catch the exception) if the localstorage value does not contain valid JSON.
release
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 if (!isLocalStorageSupported) return
try { try {
var value = window.localStorage[`${NAMESPACE}.${key}`] var value = window.localStorage[`${NAMESPACE}.${key}`]
} catch (e) {
return
}
if (value) { if (value) {
return JSON.parse(value) return JSON.parse(value)
} }
} catch (e) {
return
}
} }
} }