Skip to main content

rustauth_core/
error_codes.rs

1//! Stable API error code strings (parity with Better Auth `BASE_ERROR_CODES`).
2
3/// Stable RustAuth error-code metadata.
4pub trait ErrorCode {
5    fn as_str(&self) -> &str;
6    fn message(&self) -> &str;
7}
8
9impl<T> ErrorCode for &T
10where
11    T: ErrorCode,
12{
13    fn as_str(&self) -> &str {
14        (*self).as_str()
15    }
16
17    fn message(&self) -> &str {
18        (*self).message()
19    }
20}
21
22pub const INVALID_EMAIL: &str = "INVALID_EMAIL";
23pub const INVALID_PASSWORD: &str = "INVALID_PASSWORD";
24pub const INVALID_EMAIL_OR_PASSWORD: &str = "INVALID_EMAIL_OR_PASSWORD";
25pub const INVALID_TOKEN: &str = "INVALID_TOKEN";
26pub const INVALID_REQUEST_BODY: &str = "INVALID_REQUEST_BODY";
27pub const FIELD_NOT_ALLOWED: &str = "FIELD_NOT_ALLOWED";
28pub const USER_ALREADY_EXISTS: &str = "USER_ALREADY_EXISTS";
29pub const USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: &str = "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL";
30pub const EMAIL_NOT_VERIFIED: &str = "EMAIL_NOT_VERIFIED";
31pub const SESSION_EXPIRED: &str = "SESSION_EXPIRED";
32pub const SESSION_NOT_FRESH: &str = "SESSION_NOT_FRESH";
33pub const CREDENTIAL_ACCOUNT_NOT_FOUND: &str = "CREDENTIAL_ACCOUNT_NOT_FOUND";
34pub const NOT_FOUND: &str = "NOT_FOUND";
35pub const UNAUTHORIZED: &str = "UNAUTHORIZED";