Handle localstorage empty or failure properly

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-04-11 11:32:08 +02:00
parent c1ea6ae2a8
commit 7a12d98943
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 12 additions and 2 deletions

View File

@ -20,7 +20,12 @@ $(document).ready(function() {
* @param adminPoll
*/
function addAdminPoll(adminPoll) {
var adminPolls = JSON.parse(localStorage.getItem('admin_polls'));
var adminPolls = localStorage.getItem('admin_polls');
if (adminPolls === null) {
adminPolls = [];
} else {
adminPolls = JSON.parse(adminPolls);
}
/**
* Test if the poll is already inside the list
*/

View File

@ -32,7 +32,12 @@ $(document).ready(function () {
* @param poll
*/
function addPoll(poll) {
var polls = JSON.parse(localStorage.getItem('polls'));
var polls = localStorage.getItem('polls');
if (polls === null) {
polls = [];
} else {
polls = JSON.parse(polls);
}
/**
* Test if the poll is already inside the list