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 eitherDecodeClaims #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Lucsanszky
Copy link

As discussed here: #35 , this PR adds a utility function which preserves the error messages when decoding claims. @tekul, I was bold enough to add a String parameter to the BadClaims error. Let me know if this is acceptable or you would rather see me introduce a new error constructor.

Copy link
Owner

@tekul tekul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments. On reflection I think it's overkill having the extra function, since the original one is exactly the same (just with a fixed error message). Let me know what you think.

Jose/Jwt.hs Outdated
Nested Jwt {unJwt = p} ->
throwE
. BadClaims
$ "Encoding failed. Payload: " <> BC.unpack p
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just be something like:

Nested _ -> throwE (BadClaims "A JWS can't contain a nested JWT")

since that's why the error is being reported. It would be a coding error rather than a client issue so not something that should happen in practice. I don't think there's a need to log the encode content.

Jose/Jwt.hs Outdated
maybe
( Left
$ BadClaims
"Failed to decode claims. For more details, use `eitherDecodeClaims`."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to add an error message to BadClaims then I guess that is a breaking change for existing code which pattern matches on the error, so I'd prefer to just modify the existing decode function here to record the error, not bother with the extra eitherDecodeClaims version (which has the same signature) and just bump the library version to 1.0.

@Lucsanszky
Copy link
Author

Thanks for your review! I added the changes that you have requested, let me know if this looks any good to you.

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

Successfully merging this pull request may close these issues.

2 participants