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    /// Non-recoverable error encountered while scraping the HTML document. Indicates expected content was missing.
11    ScrapeError(String),
12    /// Error encountered during JSON serialization, originating from `serde_json`.
13    SerializeError(serde_json::Error),
14}
15
16impl From<reqwest::Error> for ScraperError {
17    fn from(error: reqwest::Error) -> Self {
18        ScraperError::FetchError(error)
19    }
20}
21
22impl From<SelectorErrorKind<'static>> for ScraperError {
23    fn from(error: SelectorErrorKind<'static>) -> Self {
24        ScraperError::ParseError(error)
25    }
26}
27
28impl From<serde_json::Error> for ScraperError {
29    fn from(error: serde_json::Error) -> Self {
30        ScraperError::SerializeError(error)
31    }
32}