Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonStorage will throw exception if key not found #74

Closed
oliverwoodings opened this issue Jan 23, 2015 · 0 comments
Closed

jsonStorage will throw exception if key not found #74

oliverwoodings opened this issue Jan 23, 2015 · 0 comments
Labels

Comments

@oliverwoodings
Copy link
Contributor

This is the code for the 'get' method of jsonStorage:

    get: function (key) {
      var raw = getStorage().getItem(getNamespacedKey(key));
      try {
        var payload = JSON.parse(raw);
        return payload.value;
      } catch (e) {
        throw new Error('Unable to parse JSON from storage');
      }
    }

If a key is not defined, this will throw an exception saying cannot parse, even though the issue is actually that it will throw a 'cannot read property value of payload'.

Really it should just return null if raw is null. I'll do a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant