-
Notifications
You must be signed in to change notification settings - Fork 397
Description
With PR #125 we can finally unwrap the Inner
error of an ValidationError
, for example to check for its underlying error, such as expiration or mis-formed token, e.g. using error.Is
However, we are not consistent in setting our inner errors. For example, for an expired map claim we set it to:
Line 129 in c435f38
vErr.Inner = errors.New("Token is expired") |
However, for our RegisteredClaims
and StandardClaims
we are setting it to:
Line 59 in c435f38
vErr.Inner = fmt.Errorf("token is expired by %v", delta) |
In other cases we are actually using constant error strings, such as:
Line 9 in 823c014
ErrInvalidKey = errors.New("key is invalid") |
I would propose to harmonize this, possibly introducing an ErrExpiredClaim
as a constant error string in this example to allow something like
token, err := jwt.Parse(...)
if err != nil && errors.Is(err, ErrExpiredClaim) {
fmt.Printf("Your token is expired")
}
We could also potentially override Is(err)
on validation error to check for the error using our flags rather than the error string.
I know that there is already a PR #100 open, but it introduces a lot of other changes and seems to be stale.