Skip to content

Commit 95b0b60

Browse files
committed
Add TokenExtractionError and TokenParsingError types to help distinguishing error source in ErrorHandler
1 parent 06ee601 commit 95b0b60

File tree

5 files changed

+781
-53
lines changed

5 files changed

+781
-53
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v4.1.0 - 2023-01-26
4+
5+
**Enhancements**
6+
7+
* Add TokenExtractionError and TokenParsingError types to help distinguishing error source in ErrorHandler [#6](https://github.com/labstack/echo-jwt/pull/6)
8+
9+
310
## v4.0.1 - 2023-01-24
411

512
**Fixes**

extrators.go renamed to extractors.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ const (
1818
extractorLimit = 20
1919
)
2020

21+
// TokenExtractionError is catch all type for all errors that occur when the token is extracted from the request. This
22+
// helps to distinguish extractor errors from token parsing errors even if custom extractors or token parsing functions
23+
// are being used that have their own custom errors.
24+
type TokenExtractionError struct {
25+
Err error
26+
}
27+
28+
// Is checks if target error is same as TokenExtractionError
29+
func (e TokenExtractionError) Is(target error) bool { return target == ErrJWTMissing } // to provide some compatibility with older error handling logic
30+
31+
func (e *TokenExtractionError) Error() string { return e.Err.Error() }
32+
func (e *TokenExtractionError) Unwrap() error { return e.Err }
33+
2134
var errHeaderExtractorValueMissing = errors.New("missing value in request header")
2235
var errHeaderExtractorValueInvalid = errors.New("invalid value in request header")
2336
var errQueryExtractorValueMissing = errors.New("missing value in the query string")

0 commit comments

Comments
 (0)