1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum AuthError {
6 #[error("Invalid credentials")]
7 InvalidCredentials,
8
9 #[error("2FA code required")]
10 TwoFactorRequired,
11
12 #[error("Invalid 2FA code")]
13 Invalid2FACode,
14
15 #[error("Account banned: {0}")]
16 AccountBanned(String),
17
18 #[error("Email not verified")]
19 EmailNotVerified,
20
21 #[error("Network error: {0}")]
22 Network(#[from] reqwest::Error),
23
24 #[error("Invalid response from server: {0}")]
25 InvalidResponse(String),
26
27 #[error("HTTP {status} from the auth server: {body}")]
28 HttpStatus { status: u16, body: String },
29
30 #[error("Missing '{field}' in the auth server response")]
31 MissingField { field: &'static str },
32
33 #[error("This Microsoft account doesn't own Minecraft")]
34 MinecraftNotOwned,
35
36 #[error("Xbox Live is not available in this account's country")]
37 XboxLiveUnavailable,
38
39 #[error("This provider does not support token verification")]
40 VerificationUnsupported,
41
42 #[error("Username must be between {min} and {max} characters")]
43 UsernameLength { min: usize, max: usize },
44
45 #[error("Username can only contain letters, numbers and underscores")]
46 UsernameCharset,
47
48 #[error("Token expired or invalid")]
49 InvalidToken,
50
51 #[error("User cancelled authentication")]
52 Cancelled,
53
54 #[error("Device code expired")]
55 DeviceCodeExpired,
56
57 #[error("Authentication timeout")]
58 Timeout,
59
60 #[error("Serialization error: {0}")]
61 Serialization(#[from] serde_json::Error),
62
63 #[error("IO error: {0}")]
64 Io(#[from] std::io::Error),
65
66 #[cfg(feature = "keyring")]
67 #[error("OS keychain error: {0}")]
68 Keyring(#[from] ::keyring::Error),
69
70 #[error("{0}")]
71 Custom(String),
72}