Skip to content

Errors ​

Sentinel Errors ​

Sentinel errors are checked with errors.Is():

go
var (
    ErrInvalidConfig        = errors.New("invalid configuration")
    ErrInvalidSecretKey     = errors.New("invalid secret key")
    ErrInvalidSigningMethod = errors.New("invalid signing method")

    ErrInvalidToken          = errors.New("invalid token")
    ErrEmptyToken            = errors.New("empty token")
    ErrAlgorithmMismatch     = errors.New("token algorithm does not match configured signing method")
    ErrTokenRevoked          = errors.New("token revoked")
    ErrTokenMissingID        = errors.New("token missing ID")
    ErrTokenTypeMismatch     = errors.New("token type mismatch")
    ErrRefreshRotationFailed = errors.New("refresh rotation failed")
    ErrTokenExpired          = errors.New("token expired")
    ErrTokenNotValidYet      = errors.New("token not valid yet")
    ErrTokenInvalidIssuer    = errors.New("token invalid issuer")
    ErrTokenInvalidAudience  = errors.New("token invalid audience")
    ErrExpirationRequired    = errors.New("token missing expiration claim")

    ErrInvalidClaims = errors.New("invalid claims")

    ErrRateLimitExceeded = errors.New("rate limit exceeded")

    ErrBlacklistNotConfigured = errors.New("blacklist not configured")

    ErrProcessorClosed = errors.New("processor closed")
    ErrStoreClosed     = errors.New("blacklist store is closed")
)

Error Overview ​

ErrorDescriptionCheck with errors.Is()
ErrInvalidConfigInvalid configurationNew(), Config.Validate()
ErrInvalidSecretKeyInvalid secret keyNew()
ErrInvalidSigningMethodInvalid signing methodNew()
ErrInvalidTokenInvalid token (signature error, etc.)Parse(), Refresh(), ParseInto(), RefreshInto(), Revoke(), IsRevoked()
ErrEmptyTokenEmpty tokenAll token operation methods
ErrAlgorithmMismatchToken algorithm doesn't match configurationParse(), Refresh(), ParseInto(), RefreshInto()
ErrTokenRevokedToken has been revokedParse(), Refresh(), ParseInto(), RefreshInto()
ErrTokenMissingIDToken is missing IDRevoke(), IsRevoked(); Refresh() / RefreshInto() when RotateRefreshTokens is enabled
ErrTokenTypeMismatchToken type mismatch (refreshing with an access token, or using a refresh token as an access token)Refresh(), RefreshInto(); Parse() / ParseInto() when RejectRefreshAsAccess is enabled
ErrRefreshRotationFailedRefresh token rotation failed (wraps the underlying blacklist store error; a full built-in store never triggers it)Refresh(), RefreshInto() (when RotateRefreshTokens is enabled)
ErrTokenExpiredToken has expiredParse(), Refresh(), ParseInto(), RefreshInto()
ErrTokenNotValidYetToken is not yet validParse(), Refresh(), ParseInto(), RefreshInto()
ErrTokenInvalidIssuerIssuer mismatchParse(), Refresh(), ParseInto(), RefreshInto(), Revoke(), IsRevoked()
ErrTokenInvalidAudienceAudience mismatchParse(), Refresh(), ParseInto(), RefreshInto(), Revoke(), IsRevoked()
ErrExpirationRequiredRequireExpiration is enabled but the token lacks expParse(), Refresh(), ParseInto(), RefreshInto()
ErrInvalidClaimsClaims validation failedCreate(), CreateRefresh(), Parse(), Refresh(), ParseInto(), RefreshInto()
ErrRateLimitExceededRate limit exceededCreate(), CreateRefresh(), Refresh(), RefreshInto()
ErrBlacklistNotConfiguredBlacklist not configured; unreachable in practice, since New() always builds oneRevoke(); Refresh() / RefreshInto() when RotateRefreshTokens is enabled
ErrProcessorClosedProcessor is closedAll methods
ErrStoreClosedStore is closedRevoke(), etc.

Check Order

ErrAlgorithmMismatch also satisfies errors.Is(err, ErrInvalidToken). Match ErrAlgorithmMismatch before ErrInvalidToken in a branch chain; otherwise an algorithm mismatch falls into the generic invalid-token branch.

When the built-in in-memory store fills up, it does not report an error — it evicts entries (fail-open), so evicted revocation records silently stop taking effect. ErrRefreshRotationFailed appears only when the underlying store truly returns an error, such as an unavailable or closed custom store backend.

By Scenario ​

Configuration Phase ​

ErrorTrigger MethodTypical Cause
ErrInvalidConfigNew()Multiple configuration items are invalid
ErrInvalidSecretKeyNew()HMAC key is less than 32 bytes or is a weak key
ErrInvalidSigningMethodNew()Not one of the 12 built-in algorithms

Token Validation ​

ErrorTrigger MethodTypical Cause
ErrEmptyTokenAll token operation methodsEmpty string passed
ErrInvalidTokenParse(), Refresh(), ParseInto(), RefreshInto(), Revoke(), IsRevoked()Signature mismatch or format error
ErrAlgorithmMismatchParse(), Refresh(), ParseInto(), RefreshInto()Token header algorithm doesn't match configuration
ErrExpirationRequiredParse(), Refresh(), ParseInto(), RefreshInto()RequireExpiration is enabled but the token lacks an exp claim
ErrTokenExpiredParse(), Refresh(), ParseInto(), RefreshInto()Past exp time
ErrTokenNotValidYetParse(), Refresh(), ParseInto(), RefreshInto()Not yet at nbf time
ErrTokenInvalidIssuerParse(), Refresh(), ParseInto(), RefreshInto(), Revoke(), IsRevoked()iss doesn't match Config.Issuer
ErrTokenInvalidAudienceParse(), Refresh(), ParseInto(), RefreshInto(), Revoke(), IsRevoked()aud doesn't match Config.ExpectedAudience
ErrTokenRevokedParse(), Refresh(), ParseInto(), RefreshInto()Token is in the blacklist
ErrTokenTypeMismatchRefresh(), RefreshInto(); Parse() / ParseInto() when RejectRefreshAsAccess is enabledRefreshing with an access token (token_type=access), or using a refresh token as an access token
ErrInvalidClaimsCreate(), CreateRefresh(), Parse(), Refresh(), ParseInto(), RefreshInto()Business validation failed
ErrTokenMissingIDRevoke(), IsRevoked(); Refresh() / RefreshInto() when RotateRefreshTokens is enabledToken is missing jti field

Rate Limiting & Blacklist ​

ErrorTrigger MethodTypical Cause
ErrRateLimitExceededCreate(), CreateRefresh(), Refresh(), RefreshInto()Exceeded window request limit
ErrBlacklistNotConfiguredRevoke(); Refresh() / RefreshInto() when RotateRefreshTokens is enabledBlacklist store not configured. New() always builds the built-in store, so this is unreachable in practice
ErrRefreshRotationFailedRefresh(), RefreshInto() (when RotateRefreshTokens is enabled)Revoking the old refresh token failed (wraps the underlying blacklist store error); no new token was issued
ErrTokenMissingIDRevoke(), IsRevoked()Token is missing jti field

Lifecycle ​

ErrorTrigger MethodTypical Cause
ErrProcessorClosedAll methodsOperating after calling Close()
ErrStoreClosedRevoke(), etc.Blacklist store is closed

Error Handling Pattern ​

go
import "errors"

claims, err := processor.Parse(tokenString)
if err != nil {
    switch {
    case errors.Is(err, jwt.ErrTokenExpired):
        // Token expired - prompt the client to refresh
    case errors.Is(err, jwt.ErrTokenRevoked):
        // Token revoked - deny access
    case errors.Is(err, jwt.ErrAlgorithmMismatch):
        // Algorithm mismatch - must be checked before ErrInvalidToken
    case errors.Is(err, jwt.ErrInvalidToken):
        // Invalid signature - deny access
    case errors.Is(err, jwt.ErrProcessorClosed):
        // System error - Processor is closed
    default:
        // Unknown error
    }
}

Error Types ​

ValidationError ​

go
type ValidationError struct {
    Field   string
    Message string
    Err     error
}

Field-level validation failure error, typically wrapped by ErrInvalidClaims and extracted with errors.As. The Err field holds an optional underlying error and the Unwrap method returns it, so errors.Is / errors.As can keep unwrapping to deeper causes. See Types & Constants → ValidationError for fields and methods.