use std::fmt;
#[derive(Debug)]
pub enum SpiderError {
Config(String),
Fetch(scrapling_fetch::FetchError),
Browser(scrapling_browser::BrowserError),
Session(String),
Checkpoint(String),
RobotsTxt(String),
Other(String),
}
impl fmt::Display for SpiderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Config(e) => write!(f, "config error: {e}"),
Self::Fetch(e) => write!(f, "fetch error: {e}"),
Self::Browser(e) => write!(f, "browser error: {e}"),
Self::Session(e) => write!(f, "session error: {e}"),
Self::Checkpoint(e) => write!(f, "checkpoint error: {e}"),
Self::RobotsTxt(e) => write!(f, "robots.txt error: {e}"),
Self::Other(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for SpiderError {}
impl From<scrapling_fetch::FetchError> for SpiderError {
fn from(e: scrapling_fetch::FetchError) -> Self {
Self::Fetch(e)
}
}
impl From<scrapling_browser::BrowserError> for SpiderError {
fn from(e: scrapling_browser::BrowserError) -> Self {
Self::Browser(e)
}
}
pub type Result<T> = std::result::Result<T, SpiderError>;