Skip to content

Commit 0b7c4e7

Browse files
committed
try/catch JSON.parse/stringify
1 parent 5462bad commit 0b7c4e7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app_modules/site/preferences/strategies.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ export const LocalStorageStrategy = stampit().methods({
3333
load () {
3434
if (!window.localStorage) { return {}; }
3535
const prefs = localStorage.getItem('prefs');
36-
return prefs && JSON.parse(prefs);
36+
try {
37+
return JSON.parse(prefs);
38+
} catch (e) {
39+
return {};
40+
}
3741
},
3842

3943
update (prefs) {
4044
if (!window.localStorage) { return; }
41-
localStorage.setItem('prefs', JSON.stringify(prefs));
45+
try {
46+
localStorage.setItem('prefs', JSON.stringify(prefs));
47+
} catch (e) {}
4248
}
4349
});
4450

0 commit comments

Comments
 (0)