How to handle parse error types #966
Unanswered
BigBoulard
asked this question in
Q&A
Replies: 1 comment 1 reply
-
(EDIT: This will no longer be true once v3 is out: you will be able to distinguish between oft-used errors using In general this library tries to avoid enumerating error types, so there isn't a complete set of errors like that. (I wrote a long explanation on why that is here, but I'm cutting it b/c it's probably not what you want to hear) I suggest you actually separate this out into smaller steps if you want that kind of micro error management. payload, err := jws.Verify(jwsPayload, ....);
if err != nil { // this is going to be a JWS error, so you can inform them as much
...
}
token, err := jwt.Parse(payload) // no need to verify here, it's already verified
// You could even do var token = jwt.New(); json.Unmarshal(&token, payload)
// if you don't need signature verification
if err != nil { // this is going to be a JWT formatting issue
...
}
if err := jwt.Validate(token, ....); err != nil { // there's something wrong in the validity
// You can use `errors.Is` with one of the predefined error type if you want. See jwt/validate.go and jwt/validate_test.go
...
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I know it probably sounds like a dumb question but I can't find how to get the different error types after parsing.
Best.
Beta Was this translation helpful? Give feedback.
All reactions