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

error handling for jwt.verify and JSON.parse #24

Open
eliasmalik opened this issue Aug 24, 2017 · 0 comments
Open

error handling for jwt.verify and JSON.parse #24

eliasmalik opened this issue Aug 24, 2017 · 0 comments

Comments

@eliasmalik
Copy link

eliasmalik commented Aug 24, 2017

jwt.verify

If you read the documentation for the verify method of the jwt package, you will see that if the secret is wrong, the method will throw an error. That means you must protect your code with a catch block unless you want your server to crash.

var tokenState = jwt.verify(cookies.token, secret);

JSON.parse

JSON.parse will also throw if its input is not a valid JSON string. You should get in the habit of protecting calls to JSON.parse with a catch block too.

@eliasmalik eliasmalik changed the title error handling for jwt.verify error handling for jwt.verify and JSON.parse Aug 24, 2017
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