Skip to content

Commit

Permalink
Catch JSON.parse() error for non-JSON objects.
Browse files Browse the repository at this point in the history
Used to work, but it seems newer browser prefere throwing errors
  • Loading branch information
zevero committed Sep 8, 2015
1 parent b45f173 commit 84d2081
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extendStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Storage.prototype.set = function(key, obj) {
}
Storage.prototype.get = function(key) {
var obj = this.getItem(key);
return obj && JSON.parse(obj);
try {
var j = JSON.parse(obj);
if (j && typeof j === "object") return j;
} catch (e) { }
return obj;
}
Storage.prototype.has = this.hasOwnProperty;
Storage.prototype.remove = this.removeItem;
Expand Down

0 comments on commit 84d2081

Please sign in to comment.