pixieve_rs/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4/// Error returned on failure to authorize with pixiv.
5#[derive(Debug)]
6pub struct AuthError {
7    reason: String,
8}
9
10impl AuthError {
11    pub fn because<T>(reason: T) -> Self
12    where
13        T: Into<String>,
14    {
15        AuthError {
16            reason: reason.into(),
17        }
18    }
19}
20
21impl Error for AuthError {
22    fn description(&self) -> &str {
23        "An error occurred while trying to authenticate."
24    }
25}
26
27impl fmt::Display for AuthError {
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        write!(
30            f,
31            "An error occurred while trying to authenticate. Reason: {:?}",
32            self.reason
33        )
34    }
35}