catch JSON.parse errors of storage metadata

This commit is contained in:
Danny Coates 2017-08-02 11:17:23 -07:00
parent f1c894d14f
commit 2897a39131
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
2 changed files with 7 additions and 7 deletions

View File

@ -29,7 +29,12 @@ class Storage {
for (let i = 0; i < this.engine.length; i++) {
const k = this.engine.key(i);
if (isFile(k)) {
fs.push(JSON.parse(this.engine.getItem(k))); // parse or whatever else
try {
fs.push(JSON.parse(this.engine.getItem(k)));
} catch (err) {
// obviously you're not a golfer
this.engine.removeItem(k);
}
}
}
return fs.sort((file1, file2) => {

View File

@ -99,12 +99,7 @@ function findMetric(href) {
}
function isFile(id) {
return ![
'referrer',
'totalDownloads',
'totalUploads',
'testpilot_ga__cid'
].includes(id);
return /^[0-9a-fA-F]{10}$/.test(id);
}
function sendEvent() {