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

Add fallback #15

Closed
franciscop opened this issue Sep 23, 2016 · 1 comment
Closed

Add fallback #15

franciscop opened this issue Sep 23, 2016 · 1 comment

Comments

@franciscop
Copy link
Owner

Add a function to allow for a fallback (possibly with localStorage):

cookies.fallback = function(obj, opts){
  if (typeof obj !== 'string') {
    console.log("Storing the data with the fallback method");
  } else {
    console.log("Retrieving the data with the fallback method");
  }
  storage(obj, opts);
}
cookies({
  token: "a string over 10kb in size that doesn't fit in the cookies"
});

It cannot default to it (as in, we cannot create and auto-integrate localStorage into cookies for example) since when setting cookies it should set the cookie or fail.

@franciscop
Copy link
Owner Author

This function could be invoked if trying to set a too large cookie with no fallback:

cookies.error = function(error, data, opt){
  throw error;
}

And in other situations where an error can exist:

  • string instead of an object for the options
  • Invalid option values: string instead of the valid expires fields, not string for domain, etc.
  • Cookie couldn't be set (maybe too large)

@franciscop franciscop transferred this issue from franciscop/brownies Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant