Skip to content

Error Codes

All authx-rs errors are represented by the AuthError enum from authx-core. The authx-axum layer maps them to HTTP responses.

VariantHTTP StatusJSON error fieldWhen it occurs
InvalidCredentials401invalid_credentialsWrong password or token
UserNotFound404user_not_foundEmail not registered
SessionNotFound401session_not_foundSession expired or invalid
EmailTaken409email_takenEmail already registered
EmailNotVerified403email_not_verifiedAction requires verified email
InvalidToken401invalid_tokenOne-time token expired or reused
AccountLocked429account_lockedToo many failed sign-in attempts
WeakPassword422weak_passwordPassword too short
Forbidden(String)403forbiddenRBAC/ABAC policy denied
HashError(String)500internal_errorArgon2 hashing failure
EncryptionError(String)500internal_errorAES-GCM encryption failure
Storage(StorageError)500internal_errorDatabase error
Internal(String)500internal_errorUnexpected internal error

AuthError::Storage wraps a StorageError:

VariantMeaning
NotFoundRecord does not exist
Conflict(String)Unique constraint violation
Database(String)Raw database error
{
"error": "invalid_credentials",
"message": "invalid credentials"
}
  • error — machine-readable code, stable across versions
  • message — human-readable description from thiserror #[error] attribute
use authx_core::error::AuthError;
match result {
Err(AuthError::InvalidCredentials) => { /* show generic login error */ }
Err(AuthError::AccountLocked) => { /* show lockout message */ }
Err(AuthError::Forbidden(reason)) => { /* log reason, show 403 page */ }
Err(e) => { /* unexpected — log and surface 500 */ }
Ok(resp) => { /* success */ }
}