diff options
author | Noah Loomans <noahloomans@gmail.com> | 2016-12-14 13:19:40 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2016-12-14 13:19:40 +0100 |
commit | d90eb26e864a4d6be73986c727b8c14b4e215f8d (patch) | |
tree | a7b061ae92e2941c29693b0284f2953b4d54e9ec /public/javascripts/favorite.js | |
parent | d67c1945b7d737d3293ea9fff95ec7f30a8f47de (diff) |
add compatibility old version localstorrage
Diffstat (limited to 'public/javascripts/favorite.js')
-rw-r--r-- | public/javascripts/favorite.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/public/javascripts/favorite.js b/public/javascripts/favorite.js index f10d954..8f48dc5 100644 --- a/public/javascripts/favorite.js +++ b/public/javascripts/favorite.js @@ -9,13 +9,18 @@ self._nodes = { } self.get = function () { - const localStorageUser = JSON.parse(window.localStorage.getItem('fav')) - if (localStorageUser == null) return - - const correctedUser = USERS.filter(user => - user.type === localStorageUser.type && - user.value === localStorageUser.value)[0] - return correctedUser + try { + const localStorageUser = JSON.parse(window.localStorage.getItem('fav')) + if (localStorageUser == null) return + + const correctedUser = USERS.filter(user => + user.type === localStorageUser.type && + user.value === localStorageUser.value)[0] + return correctedUser + } catch (e) { + self.delete() + return + } } self.set = function (user) { |