pub enum AuthError {
Show 24 variants
BadRequest(String),
InvalidRequest(String),
Validation(String),
InvalidCredentials,
Unauthenticated,
AuthenticationFailed(String),
SessionNotFound,
Forbidden(String),
BannedUser(String),
Unauthorized,
UserNotFound,
NotFound(String),
Conflict(String),
PayloadTooLarge(String),
UnprocessableEntity(String),
RateLimited,
NotImplemented(String),
Config(String),
Database(DatabaseError),
Serialization(Error),
Plugin {
plugin: String,
message: String,
},
Internal(String),
PasswordHash(String),
Jwt(Error),
}Expand description
Authentication framework error types.
Each variant maps to an HTTP status code via AuthError::status_code.
Use AuthError::to_auth_response to produce a standardized JSON response
matching the better-auth OpenAPI spec: { "message": "..." }.
Variants§
BadRequest(String)
InvalidRequest(String)
Validation(String)
InvalidCredentials
Unauthenticated
AuthenticationFailed(String)
SessionNotFound
Forbidden(String)
BannedUser(String)
UserNotFound
NotFound(String)
Conflict(String)
PayloadTooLarge(String)
UnprocessableEntity(String)
RateLimited
NotImplemented(String)
Config(String)
Database(DatabaseError)
Serialization(Error)
Plugin
Internal(String)
PasswordHash(String)
Jwt(Error)
Implementations§
Source§impl AuthError
impl AuthError
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
HTTP status code for this error.
Sourcepub fn code_from_message(message: &str) -> String
pub fn code_from_message(message: &str) -> String
Derive the error code from the message, matching the TS better-auth
behavior: message.toUpperCase().replace(/ /g, "_").replace(/[^A-Z0-9_]/g, "").
Sourcepub fn error_payload(&self) -> (u16, String, String)
pub fn error_payload(&self) -> (u16, String, String)
Compute the HTTP status, error code, and user-facing message.
Internal errors (500) are logged and replaced with a generic message to avoid leaking details.
Sourcepub fn to_auth_response(self) -> AuthResponse
pub fn to_auth_response(self) -> AuthResponse
Convert this error into a standardized AuthResponse matching the
better-auth spec: { "code": "...", "message": "..." }.
Named to_auth_response to avoid collision with Axum’s
IntoResponse::into_response when the axum feature is enabled.
pub fn bad_request(message: impl Into<String>) -> Self
pub fn forbidden(message: impl Into<String>) -> Self
pub fn banned_user(message: impl Into<String>) -> Self
pub fn not_found(message: impl Into<String>) -> Self
pub fn conflict(message: impl Into<String>) -> Self
pub fn payload_too_large(message: impl Into<String>) -> Self
pub fn not_implemented(message: impl Into<String>) -> Self
pub fn plugin(plugin: &str, message: impl Into<String>) -> Self
pub fn config(message: impl Into<String>) -> Self
pub fn internal(message: impl Into<String>) -> Self
pub fn validation(message: impl Into<String>) -> Self
pub fn authentication_failed(message: impl Into<String>) -> Self
Trait Implementations§
Source§impl Error for AuthError
impl Error for AuthError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()