#[derive(Debug)]
pub enum Error {
Io(std::io::Error),
Parse(String),
Url(url::ParseError),
ExtractionBR(String),
ExtractionSE(String),
Ring(ring::error::Unspecified),
NoSessionCreator,
Custom(String)
}
impl Error {
pub fn custom<A: Into<String>>(message: A) -> Error {
Error::Custom(message.into())
}
}
impl std::fmt::Display for Error {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
let content = match self {
Error::Io(inner_error) => format!("io error: {}", inner_error),
Error::Parse(detail) => format!("parse error: {}", detail),
Error::Url(detail) => format!("url parse error: {}", detail),
Error::ExtractionBR(detail) => format!("extraction bad request: {}", detail),
Error::ExtractionSE(detail) => format!("extraction server error: {}", detail),
Error::Ring(e) => format!("ring error: {}", e),
Error::NoSessionCreator => format!("the session extractor requires a SessionCreator struct to work, see documentation"),
Error::Custom(e) => format!("{}", e)
};
write!(formatter, "{}", content)
}
}
impl std::error::Error for Error {}