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
use thiserror::Error;

/// Represents any kind of error that can occur when dealing with the Reddit API.
#[derive(Error, Debug)]
pub enum RedditError {
    /// We request data for a non-existent subreddit or user etc.
    #[error("Resource not found: '{0}'")]
    ResourceNotFound(String),

    /// The request that fetches the Reddit access token for our app failed.
    #[error("Failed to fetch Reddit access token for client_id '{0}'")]
    FailedToFetchAccessToken(String),

    /// Invalid domain was given for the request
    #[error("Domain '{0}' is not a valid Reddit API domain")]
    InvalidDomain(String),

    /// Some other HTTP error occured.
    #[error("HTTP Error: `{0}`")]
    HttpError(#[from] reqwest::Error),

    /// Deserialization to our structs failed.
    ///
    /// Possible causes:
    /// * Our struct definitions are wrong
    /// * We didn't check for an error status and we're trying to parse an error response to our structs
    /// * Reddit sent a malformed response (incredibly unlikely)
    #[error("JSON Error: `{0}`")]
    JsonError(#[from] serde_json::Error),
}