More safely parse JSON from localStorage
This commit is contained in:
parent
a2cb32cce2
commit
dbfd45794a
|
@ -40,7 +40,12 @@ class UserSettings {
|
||||||
case Boolean:
|
case Boolean:
|
||||||
this[key] = localStorage[key] === "true";
|
this[key] = localStorage[key] === "true";
|
||||||
case Object:
|
case Object:
|
||||||
|
try {
|
||||||
this[key] = JSON.parse(localStorage[key]);
|
this[key] = JSON.parse(localStorage[key]);
|
||||||
|
} catch(e) {
|
||||||
|
console.error(`LocalStorage: parsing key ${key}: ${e}`);
|
||||||
|
delete(this[key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user