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>) -> AuthError
pub fn forbidden(message: impl Into<String>) -> AuthError
pub fn banned_user(message: impl Into<String>) -> AuthError
pub fn not_found(message: impl Into<String>) -> AuthError
pub fn conflict(message: impl Into<String>) -> AuthError
pub fn payload_too_large(message: impl Into<String>) -> AuthError
pub fn not_implemented(message: impl Into<String>) -> AuthError
pub fn plugin(plugin: &str, message: impl Into<String>) -> AuthError
pub fn config(message: impl Into<String>) -> AuthError
pub fn internal(message: impl Into<String>) -> AuthError
pub fn validation(message: impl Into<String>) -> AuthError
pub fn authentication_failed(message: impl Into<String>) -> AuthError
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()
Source§impl From<DatabaseError> for AuthError
impl From<DatabaseError> for AuthError
Source§fn from(source: DatabaseError) -> AuthError
fn from(source: DatabaseError) -> AuthError
Auto Trait Implementations§
impl !RefUnwindSafe for AuthError
impl !UnwindSafe for AuthError
impl Freeze for AuthError
impl Send for AuthError
impl Sync for AuthError
impl Unpin for AuthError
impl UnsafeUnpin for AuthError
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.