Skip to content

Errors

Sentinel Errors

All errors are checked using 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")
    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.)Validate(), Refresh(), ValidateInto(), RefreshInto(), Revoke(), IsRevoked()
ErrEmptyTokenEmpty tokenAll token operation methods
ErrAlgorithmMismatchToken algorithm doesn't match configurationValidate(), Refresh(), ValidateInto(), RefreshInto()
ErrTokenRevokedToken has been revokedValidate(), Refresh(), ValidateInto(), RefreshInto()
ErrTokenMissingIDToken is missing IDRevoke(), IsRevoked()
ErrTokenTypeMismatchToken type mismatch (refreshing with an access token)Refresh(), RefreshInto()
ErrTokenExpiredToken has expiredValidate(), Refresh(), ValidateInto(), RefreshInto()
ErrTokenNotValidYetToken is not yet validValidate(), Refresh(), ValidateInto(), RefreshInto()
ErrTokenInvalidIssuerIssuer mismatchValidate(), Refresh(), ValidateInto(), RefreshInto(), Revoke(), IsRevoked()
ErrTokenInvalidAudienceAudience mismatchValidate(), Refresh(), ValidateInto(), RefreshInto(), Revoke(), IsRevoked()
ErrExpirationRequiredRequireExpiration is enabled but the token lacks expValidate(), Refresh(), ValidateInto(), RefreshInto()
ErrInvalidClaimsClaims validation failedCreate(), CreateRefresh(), Validate(), Refresh(), ValidateInto(), RefreshInto()
ErrRateLimitExceededRate limit exceededCreate(), CreateRefresh(), Refresh(), RefreshInto()
ErrBlacklistNotConfiguredBlacklist not configuredRevoke()
ErrProcessorClosedProcessor is closedAll methods
ErrStoreClosedStore is closedRevoke(), etc.

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
ErrInvalidTokenValidate(), Refresh(), ValidateInto(), RefreshInto(), Revoke(), IsRevoked()Signature mismatch or format error
ErrAlgorithmMismatchValidate(), Refresh(), ValidateInto(), RefreshInto()Token header algorithm doesn't match configuration
ErrExpirationRequiredValidate(), Refresh(), ValidateInto(), RefreshInto()RequireExpiration is enabled but the token lacks an exp claim
ErrTokenExpiredValidate(), Refresh(), ValidateInto(), RefreshInto()Past exp time
ErrTokenNotValidYetValidate(), Refresh(), ValidateInto(), RefreshInto()Not yet at nbf time
ErrTokenInvalidIssuerValidate(), Refresh(), ValidateInto(), RefreshInto(), Revoke(), IsRevoked()iss doesn't match Config.Issuer
ErrTokenInvalidAudienceValidate(), Refresh(), ValidateInto(), RefreshInto(), Revoke(), IsRevoked()aud doesn't match Config.ExpectedAudience
ErrTokenRevokedValidate(), Refresh(), ValidateInto(), RefreshInto()Token is in the blacklist
ErrTokenTypeMismatchRefresh(), RefreshInto()Refreshing with an access token (token_type=access)
ErrInvalidClaimsCreate(), CreateRefresh(), Validate(), Refresh(), ValidateInto(), RefreshInto()Business validation failed
ErrTokenMissingIDRevoke(), IsRevoked()Token is missing jti field

Rate Limiting & Blacklist

ErrorTrigger MethodTypical Cause
ErrRateLimitExceededCreate(), CreateRefresh(), Refresh(), RefreshInto()Exceeded window request limit
ErrBlacklistNotConfiguredRevoke()Blacklist store not configured
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, valid, err := processor.Validate(tokenString)
if err != nil {
    switch {
    case errors.Is(err, jwt.ErrTokenExpired):
        // Token expired - prompt user to refresh
    case errors.Is(err, jwt.ErrTokenRevoked):
        // Token revoked - deny access
    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. See Types & Constants → ValidationError for details.