From b15af985142dea1769a4a119201c1126a9a9413a Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 17 Feb 2023 21:12:15 +0100 Subject: [PATCH] Adjusting the error checking example This PR adjusts the error checking example so that a check for an invalid signature is also included. See discussion in #143 --- errors.go | 2 +- example_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/errors.go b/errors.go index 10ac8835..b530f399 100644 --- a/errors.go +++ b/errors.go @@ -77,7 +77,7 @@ func (e *ValidationError) valid() bool { // Is checks if this ValidationError is of the supplied error. We are first checking for the exact error message // by comparing the inner error message. If that fails, we compare using the error flags. This way we can use -// custom error messages (mainly for backwards compatability) and still leverage errors.Is using the global error variables. +// custom error messages (mainly for backwards compatibility) and still leverage errors.Is using the global error variables. func (e *ValidationError) Is(err error) bool { // Check, if our inner error is a direct match if errors.Is(errors.Unwrap(e), err) { diff --git a/example_test.go b/example_test.go index ddf49ccb..94eebaf0 100644 --- a/example_test.go +++ b/example_test.go @@ -106,6 +106,9 @@ func ExampleParse_errorChecking() { fmt.Println("You look nice today") } else if errors.Is(err, jwt.ErrTokenMalformed) { fmt.Println("That's not even a token") + } else if errors.Is(err, jwt.ErrTokenSignatureInvalid) { + // Invalid signature + fmt.Println("Invalid signature") } else if errors.Is(err, jwt.ErrTokenExpired) || errors.Is(err, jwt.ErrTokenNotValidYet) { // Token is either expired or not active yet fmt.Println("Timing is everything")