yggdrasil_authenticator/model/
auth_error.rs

1use serde::Deserialize;
2
3/// Represents an authentication error in Yggdrasil's authentication system.
4///
5/// This struct contains information about the error encountered during authentication,
6/// including a general error identifier, a detailed error message, and the cause of the error.
7#[derive(Deserialize, Debug, Clone)]
8pub struct AuthError {
9    /// A general identifier for the error.
10    pub error: String,
11
12    /// A detailed message explaining the error.
13    #[serde(rename = "errorMessage")]
14    pub error_message: String,
15
16    /// The cause of the error.
17    pub cause: String,
18}
19
20impl AuthError {
21    /// Creates a new `AuthError` with the provided error details.
22    ///
23    /// # Arguments
24    ///
25    /// * `error` - A general identifier for the error.
26    /// * `error_message` - A detailed message explaining the error.
27    /// * `cause` - The cause of the error.
28    ///
29    /// # Returns
30    ///
31    /// A new `AuthError` instance.
32    pub fn new(error: String, error_message: String, cause: String) -> AuthError {
33        AuthError {
34            error,
35            error_message,
36            cause,
37        }
38    }
39}
40
41impl std::fmt::Display for AuthError {
42    /// Formats the `AuthError` for display.
43    ///
44    /// # Arguments
45    ///
46    /// * `f` - The formatter to write to.
47    ///
48    /// # Returns
49    ///
50    /// A result indicating success or failure.
51    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
52        write!(f, "{}: {}", self.error, self.error_message)
53    }
54}
55
56impl std::error::Error for AuthError {
57}