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

Unwrap for ValidationError #125

Merged
merged 1 commit into from Nov 15, 2021
Merged

Unwrap for ValidationError #125

merged 1 commit into from Nov 15, 2021

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.

None yet

3 participants