reqwest_scraper/
error.rs

1//! Scraping Error
2//!
3use thiserror::Error;
4
5/// Scraping Error
6#[derive(Error, Debug)]
7pub enum ScraperError {
8    /// JsonPath Error
9    #[cfg(feature = "json")]
10    #[error(transparent)]
11    SerdeJsonError(#[from] serde_path_to_error::Error<serde_json::Error>),
12
13    /// JsonPath Error
14    #[cfg(feature = "jsonpath")]
15    #[error(transparent)]
16    JsonPathError(#[from] jsonpath_lib::JsonPathError),
17
18    /// JsonPath Match Error
19    #[cfg(feature = "jsonpath")]
20    #[error("jsonpath match error:{0}")]
21    JsonPathMatchError(String),
22
23    /// Json Deserialize Error
24    #[cfg(feature = "jsonpath")]
25    #[error(transparent)]
26    JsonDeserializeError(#[from] serde_json::Error),
27
28    /// Css Selector Error
29    #[cfg(feature = "css_selector")]
30    #[error("css selector error: {0}")]
31    CssSelectorError(String),
32
33    /// JsonPath Match Error
34    #[cfg(feature = "css_selector")]
35    #[error("css selector match error:{0}")]
36    CssSelectorMatchError(String),
37
38    /// Html Document Parse Error
39    #[cfg(feature = "xpath")]
40    #[error(transparent)]
41    HtmlParseError(#[from] libxml::parser::XmlParseError),
42
43    /// XPath Evaluate Error
44    #[cfg(feature = "xpath")]
45    #[error("{0}")]
46    XPathError(String),
47
48    /// IO Error
49    #[error(transparent)]
50    IOError(#[from] reqwest::Error),
51
52    /// IO Error
53    #[cfg(feature = "middleware")]
54    #[error(transparent)]
55    MiddlewareIOError(#[from] reqwest_middleware::Error),
56
57    /// Http response failed
58    #[error("http request for \"{0}\" error code:{1}, body text:{2}")]
59    HttpError(String, u16, String),
60}
61
62#[cfg(feature = "css_selector")]
63impl<'a> From<scraper::error::SelectorErrorKind<'a>> for ScraperError {
64    fn from(value: scraper::error::SelectorErrorKind<'a>) -> Self {
65        Self::CssSelectorError(value.to_string())
66    }
67}
68
69/// Result
70pub type Result<T> = std::result::Result<T, ScraperError>;