grscraper/
errors.rs

1use scraper::error::SelectorErrorKind;
2
3/// Custom error type for handling errors in the Goodreads metadata scraper.
4#[derive(Debug)]
5pub enum ScraperError {
6    /// Error that occurs during the HTTP request to Goodreads, originating from `reqwest`.
7    FetchError(reqwest::Error),
8    /// Error encountered while parsing the HTML document, originating from `scraper`.
9    ParseError(scraper::error::SelectorErrorKind<'static>),
10    /// Error encountered during JSON serialization, originating from `serde_json`.
11    SerializeError(serde_json::Error),
12}
13
14impl From<reqwest::Error> for ScraperError {
15    fn from(error: reqwest::Error) -> Self {
16        ScraperError::FetchError(error)
17    }
18}
19
20impl From<SelectorErrorKind<'static>> for ScraperError {
21    fn from(error: SelectorErrorKind<'static>) -> Self {
22        ScraperError::ParseError(error)
23    }
24}
25
26impl From<serde_json::Error> for ScraperError {
27    fn from(error: serde_json::Error) -> Self {
28        ScraperError::SerializeError(error)
29    }
30}