-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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`." |
There was a problem hiding this comment.
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.
9ba1b91
to
1ed2004
Compare
Thanks for your review! I added the changes that you have requested, let me know if this looks any good to you. |
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 theBadClaims
error. Let me know if this is acceptable or you would rather see me introduce a new error constructor.