Skip to content

Error Reference

中文 | English

The unified core error type is SaTokenError (in sa-token-core). User-visible Display / message() text is English (from #[error(...)]).

SaTokenResult

rust
pub type SaTokenResult<T> = Result<T, SaTokenError>;

Most business and library APIs return this alias. Use err.is_auth_error() / err.is_authz_error() for coarse classification.

Application-level short message constants (not SaTokenError variants) live in sa_token_core::error::messages (for example INVALID_CREDENTIALS).


Groups by domain

Groups below mirror sa-token-core/src/error.rs. Each row has a one-line typical trigger.

Token / login

VariantTypical trigger
TokenNotFoundToken missing in storage, or already expired and removed
InvalidToken(String)Token format or content failed validation
TokenExpiredToken explicitly judged expired
NotLoginCurrent request context is not logged in
TokenInactiveToken exists but is inactive (frozen / not enabled)
TokenEmptyEmpty token string passed in
TokenTooShortToken shorter than the configured minimum
LoginIdNotNumberlogin_id required to be numeric but failed to parse
SessionNotFoundSession missing or already deleted

Authorization (permission / role / terminal)

VariantTypical trigger
PermissionDeniedPermission check failed (no specific code)
PermissionDeniedDetail(String)Missing a named permission
RoleDenied(String)Missing a named role
TerminalDenied { expected, actual }Device/terminal does not match the allowed pattern

Account safety

VariantTypical trigger
AccountBanned(String)Account banned until the given time
AccountKickedOutSession forcibly kicked
AccountReplacedLogin replaced on another device
NotSafe(String)Secondary auth not completed for a service
DisableService { service, level }Account disabled for a service at a level
SameTokenInvalidSame-Token header missing or mismatched
BasicAuthFailed { realm }HTTP Basic credentials missing or wrong
SignInvalidRequest signature mismatch
SignTimestampExpiredSignature timestamp missing or outside the window
TempTokenNotFoundTemp token missing or already deleted
TempTokenExpiredTemp token past expire_at

Initialization

VariantTypical trigger
NotInitializedGlobal APIs used before StpUtil::try_init_manager (or equivalent)
AlreadyInitializedGlobal Manager initialized twice

Storage / config / serialization / internal

VariantTypical trigger
StorageError(String)Underlying SaStorage operation failed
ConfigError(String)Invalid config (missing storage, bad JWT secret, …), often from try_build
SerializationError(String)Encode/decode failure. Includes serde_json::Error and mapped SerializerError (EncodeFailed / DecodeFailed / FormatMismatch / VersionIncompatible from pluggable SaSerializer)
InternalError(String)Unexpected internal failure

OAuth2

VariantTypical trigger
OAuth2ClientNotFoundClient not registered
OAuth2InvalidCredentialsInvalid client_id / secret
OAuth2ClientIdMismatchToken/code does not match client_id
OAuth2RedirectUriMismatchredirect_uri does not match registration
OAuth2CodeNotFoundAuthorization code missing or expired
OAuth2AccessTokenNotFoundAccess token missing or expired
OAuth2RefreshTokenNotFoundOAuth2 refresh token missing or expired
OAuth2InvalidRefreshTokenOAuth2 refresh token payload invalid
OAuth2InvalidScopeInvalid scope data
OAuth2PkceRequiredcode_verifier required but missing
OAuth2PkceMismatchPKCE verification failed
OAuth2TokenRevokeFailed(String)Revoke failed
OAuth2UnsupportedGrantUnsupported grant_type
OAuth2PkceRequiredForPublicClientPublic client did not use PKCE S256

SSO

VariantTypical trigger
InvalidTicketTicket missing or invalid
TicketExpiredTicket expired
ServiceMismatchService URL does not match registration
SsoSessionNotFoundSSO session missing
SsoSignInvalidSSO request signature invalid

Nonce / refresh (sa-token refresh tokens)

VariantTypical trigger
NonceAlreadyUsedNonce already consumed (possible replay)
InvalidNonceFormatInvalid nonce format
InvalidNonceTimestampNonce timestamp invalid or expired
RefreshTokenNotFoundRefresh token missing or expired
RefreshTokenInvalidDataRefresh token payload invalid
RefreshTokenMissingLoginIdRefresh token missing login_id
RefreshTokenInvalidExpireTimeInvalid expire-time format in refresh token

Matching example

rust
use sa_token_core::{SaTokenError, SaTokenResult};

fn map_status(err: SaTokenError) -> u16 {
    match err {
        SaTokenError::NotLogin | SaTokenError::TokenNotFound | SaTokenError::TokenExpired => 401,
        e if e.is_authz_error() => 403,
        SaTokenError::NotInitialized | SaTokenError::ConfigError(_) => 500,
        _ => 400,
    }
}

MIT OR Apache-2.0