Skip to content

Commit

Permalink
Merge pull request #16 from walmartlabs/fix-ie-err-4047
Browse files Browse the repository at this point in the history
ignore "Invalid Arguments" error when IE tries to `setItem` with certain
  • Loading branch information
kpdecker committed Feb 19, 2014
2 parents abfb1ab + d333c7b commit 653f6a9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions local-cache.js
Expand Up @@ -43,6 +43,12 @@ this.LocalCache = (function constructor(localStorage) {
|| error.name === 'NS_ERROR_DOM_QUOTA_REACHED';
}

function isStorageBug(error) {
// IE stores localStorage as XML internally, as a result, some
// characters cause this error to be thrown.
return error.description === 'Invalid Argument.'
}

function checkStorage() {
function tryStore() {
localStorage.setItem('available-test', '1');
Expand All @@ -60,7 +66,7 @@ this.LocalCache = (function constructor(localStorage) {
// If we have a quota error, try one more time.
flushExpired();

tryStore()
tryStore();

// We worked this time, full steam ahead.
return;
Expand Down Expand Up @@ -177,7 +183,8 @@ this.LocalCache = (function constructor(localStorage) {
if (cullList.length) {
removeKey(cullList[0].key);
}
} else {
// We ignore if there is a ttl set - which indicates that it is not actual content
} else if (!isStorageBug(err) || !ttl) {
throw err;
}
}
Expand Down

0 comments on commit 653f6a9

Please sign in to comment.