reddit/error.rs
1/// Error type for this library
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4 #[error(transparent)]
5 Reqwest(#[from] reqwest::Error),
6
7 /// Json parse error
8 #[error("failed to parse json")]
9 Json {
10 /// The data that was being parsed
11 data: Box<str>,
12
13 /// The parse error
14 #[source]
15 error: serde_json::Error,
16 },
17
18 /// Failed to find subreddit
19 #[error("failed to locate the subreddit")]
20 SubredditNotFound,
21}
22
23impl Error {
24 /// Returns `true` if the error type is `SubredditNotFound`, `false` otherwise.
25 pub fn is_subreddit_not_found(&self) -> bool {
26 matches!(self, Self::SubredditNotFound)
27 }
28}