steam_mobile/
errors.rs

1//! Main error type of `SteamAuthenticator`.
2//!
3//! If an internal error occurs, it simply delegates to the correct error type.
4//! Generally, this isn't a good strategy, but 90% of the errors happen because of a
5//! misconfiguration, they are not recoverable and we choose to just fail fast.
6//!
7//!
8//! For a general explanation of EResults, check: [steam errors website](https://steamerrors.com/).
9use thiserror::Error;
10
11#[allow(missing_docs)]
12#[derive(Error, Debug)]
13pub enum AuthError {
14    #[error(transparent)]
15    AuthenticatorError(#[from] LinkerError),
16    #[error(transparent)]
17    ApiKeyError(#[from] ApiKeyError),
18    #[error(transparent)]
19    Login(#[from] LoginError),
20    #[error(transparent)]
21    MobileAuthFile(#[from] MobileAuthFileError),
22    #[error(transparent)]
23    InternalError(#[from] InternalError),
24}
25
26#[allow(missing_docs)]
27#[derive(Error, Debug)]
28pub enum ConfirmationError {
29    #[error("General Failure: `{0}`")]
30    GeneralError(String),
31}
32
33#[allow(missing_docs)]
34#[derive(Error, Debug)]
35pub enum ApiKeyError {
36    #[error("General Failure: `{0}`")]
37    GeneralError(String),
38    #[error("This key is unavailable for registering.")]
39    AccessDenied,
40    #[error("Key not yet registered.")]
41    NotRegistered,
42    #[error(transparent)]
43    InternalError(#[from] InternalError),
44}
45
46#[allow(missing_docs)]
47#[derive(Error, Debug)]
48pub enum LoginError {
49    #[error("Message returned: `{0}`")]
50    GeneralFailure(String),
51    #[error("Parental unlock error `{0}`")]
52    ParentalUnlock(String),
53    #[error("Steam Guard Mobile is not enabled. Email codes are not supported.")]
54    Need2FA,
55    #[error("Account name or password entered are incorrect.")]
56    IncorrectCredentials,
57    #[error("Requires a captcha code. If a previous attempt was made, the captcha was probably incorrect. \
58    Captcha GUID: `{0}`", .captcha_guid)]
59    CaptchaRequired { captcha_guid: String },
60    #[error(transparent)]
61    InternalError(#[from] InternalError),
62    #[error(transparent)]
63    TotpError(#[from] steam_totp::error::TotpError),
64}
65
66/// Errors related to the Authenticator Linker.
67#[allow(missing_docs)]
68#[derive(Error, Debug)]
69pub enum LinkerError {
70    #[error("{0}")]
71    GeneralFailure(String),
72    #[error("An authenticator is already linked to this account. Please remove the old one before adding a new one.")]
73    AuthenticatorPresent,
74    #[error("The SMS code you entered is incorrect.")]
75    BadSMSCode,
76    #[error("We were unable to generate the correct codes. Perhaps something changed?")]
77    UnableToGenerateCorrectCodes,
78    #[error(transparent)]
79    InternalError(#[from] InternalError),
80    #[error(transparent)]
81    TotpError(#[from] steam_totp::error::TotpError),
82}
83
84/// Errors related to the Authenticator Linker.
85#[allow(missing_docs)]
86#[derive(Error, Debug)]
87pub enum MobileAuthFileError {
88    #[error(transparent)]
89    InternalError(#[from] InternalError),
90
91    #[error("{0}")]
92    GeneralFailure(String),
93}
94
95/// Errors from networking or failure to deserialize internal types.
96#[allow(missing_docs)]
97#[derive(Error, Debug)]
98pub enum InternalError {
99    #[error("`{0}`")]
100    GeneralFailure(String),
101
102    #[error(transparent)]
103    HttpError(#[from] reqwest::Error),
104
105    #[error(
106        "A deserialization error has occurred. This indicates a change in the response or an unexpected situation. \
107         Please report this issue."
108    )]
109    DeserializationError(#[from] serde_json::Error),
110}