1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Main error type of `SteamAuthenticator`.
//!
//! If an internal error occurs, it simply delegates to the correct error type.
//! Generally, this isn't a good strategy, but 90% of the errors happen because of a
//! misconfiguration, they are not recoverable and we choose to just fail fast.
//!
//!
//! For a general explanation of EResults, check: [steam errors website](https://steamerrors.com/).
use thiserror::Error;

#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum AuthError {
    #[error(transparent)]
    AuthenticatorError(#[from] LinkerError),
    #[error(transparent)]
    ApiKeyError(#[from] ApiKeyError),
    #[error(transparent)]
    Login(#[from] LoginError),
    #[error(transparent)]
    MobileAuthFile(#[from] MobileAuthFileError),
    #[error(transparent)]
    InternalError(#[from] InternalError),
}

#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum ConfirmationError {
    #[error("General Failure: `{0}`")]
    GeneralError(String),
}

#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum ApiKeyError {
    #[error("General Failure: `{0}`")]
    GeneralError(String),
    #[error("This key is unavailable for registering.")]
    AccessDenied,
    #[error("Key not yet registered.")]
    NotRegistered,
    #[error(transparent)]
    InternalError(#[from] InternalError),
}

#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum LoginError {
    #[error("Message returned: `{0}`")]
    GeneralFailure(String),
    #[error("Parental unlock error `{0}`")]
    ParentalUnlock(String),
    #[error("Steam Guard Mobile is not enabled. Email codes are not supported.")]
    Need2FA,
    #[error("Account name or password entered are incorrect.")]
    IncorrectCredentials,
    #[error("Requires a captcha code. If a previous attempt was made, the captcha was probably incorrect. \
    Captcha GUID: `{0}`", .captcha_guid)]
    CaptchaRequired { captcha_guid: String },
    #[error(transparent)]
    InternalError(#[from] InternalError),
    #[error(transparent)]
    TotpError(#[from] steam_totp::error::TotpError),
}

/// Errors related to the Authenticator Linker.
#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum LinkerError {
    #[error("{0}")]
    GeneralFailure(String),
    #[error("An authenticator is already linked to this account. Please remove the old one before adding a new one.")]
    AuthenticatorPresent,
    #[error("The SMS code you entered is incorrect.")]
    BadSMSCode,
    #[error("We were unable to generate the correct codes. Perhaps something changed?")]
    UnableToGenerateCorrectCodes,
    #[error(transparent)]
    InternalError(#[from] InternalError),
    #[error(transparent)]
    TotpError(#[from] steam_totp::error::TotpError),
}

/// Errors related to the Authenticator Linker.
#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum MobileAuthFileError {
    #[error(transparent)]
    InternalError(#[from] InternalError),

    #[error("{0}")]
    GeneralFailure(String),
}

/// Errors from networking or failure to deserialize internal types.
#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum InternalError {
    #[error("`{0}`")]
    GeneralFailure(String),

    #[error(transparent)]
    HttpError(#[from] reqwest::Error),

    #[error(
        "A deserialization error has occurred. This indicates a change in the response or an unexpected situation. \
         Please report this issue."
    )]
    DeserializationError(#[from] serde_json::Error),
}