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
//! The error type of the authentication flows.
use crate::base::generated::steam_language::EResult;
use crate::error::SteamError;
/// Returned when `SteamAuthentication` fails to authenticate.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum AuthenticationException {
/// The operation failed with a Steam result code.
#[error("{message} with result {result:?}.")]
Failed {
/// The message that describes the error.
message: String,
/// The result code that describes the error.
result: EResult,
},
/// The operation failed for a reason that has no result code.
#[error("{message}")]
Other {
/// The message that describes the error.
message: String,
},
}
impl AuthenticationException {
/// Creates an error that carries a Steam result code.
pub fn failed(message: impl Into<String>, result: EResult) -> Self {
AuthenticationException::Failed {
message: message.into(),
result,
}
}
/// Creates an error without a result code.
pub fn other(message: impl Into<String>) -> Self {
AuthenticationException::Other {
message: message.into(),
}
}
/// The result of the authentication request, if the failure carried one.
pub fn result(&self) -> Option<EResult> {
match self {
AuthenticationException::Failed { result, .. } => Some(*result),
AuthenticationException::Other { .. } => None,
}
}
}
impl From<AuthenticationException> for SteamError {
/// Converts into [`SteamError`].
fn from(value: AuthenticationException) -> Self {
SteamError::Authentication(value.to_string())
}
}