Skip to content

Conversation

kdeberk
Copy link
Contributor

@kdeberk kdeberk commented Nov 11, 2021

This PR adds a single Unwrap function to the ValidationError.

With this function, it is possible to call errors.Is(err, target) or errors.As(err, &target) with the error returned by e.g. ParseWithClaims.

More specifically, it allows one to replace

       _, err := jwt.ParseWithClaims(...)

	var valErr *jwt.ValidationError
	if errors.As(err, &valErr) {
		if errors.Is(valErr, myErrorType) {
			// do X
		} else {
                        // do Y
                }
	}

with

       _, err := jwt.ParseWithClaims(...)
       if errors.Is(err, myErrorType) {
           // do X
       }  else {
           // do Y
       }

@mfridman mfridman merged commit 823c014 into golang-jwt:main Nov 15, 2021
@kdeberk kdeberk deleted the unwrap-error branch November 15, 2021 15:24
oxisto pushed a commit to moneszarrugh/jwt that referenced this pull request Feb 21, 2023
oxisto pushed a commit to twocs/jwt that referenced this pull request Mar 29, 2023
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.

3 participants