Skip to content

Commit

Permalink
Add TokenExtractionError and TokenParsingError types to help distingu…
Browse files Browse the repository at this point in the history
…ishing error source in ErrorHandler
  • Loading branch information
aldas committed Jan 26, 2023
1 parent 06ee601 commit 95b0b60
Show file tree
Hide file tree
Showing 5 changed files with 781 additions and 53 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v4.1.0 - 2023-01-26

**Enhancements**

* Add TokenExtractionError and TokenParsingError types to help distinguishing error source in ErrorHandler [#6](https://github.com/labstack/echo-jwt/pull/6)


## v4.0.1 - 2023-01-24

**Fixes**
Expand Down
13 changes: 13 additions & 0 deletions extrators.go → extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ const (
extractorLimit = 20
)

// TokenExtractionError is catch all type for all errors that occur when the token is extracted from the request. This
// helps to distinguish extractor errors from token parsing errors even if custom extractors or token parsing functions
// are being used that have their own custom errors.
type TokenExtractionError struct {
Err error
}

// Is checks if target error is same as TokenExtractionError
func (e TokenExtractionError) Is(target error) bool { return target == ErrJWTMissing } // to provide some compatibility with older error handling logic

func (e *TokenExtractionError) Error() string { return e.Err.Error() }
func (e *TokenExtractionError) Unwrap() error { return e.Err }

var errHeaderExtractorValueMissing = errors.New("missing value in request header")
var errHeaderExtractorValueInvalid = errors.New("invalid value in request header")
var errQueryExtractorValueMissing = errors.New("missing value in the query string")
Expand Down
Loading

0 comments on commit 95b0b60

Please sign in to comment.