use std::fmt::Debug;
use airac::AIRAC;
use crate::parts::{EAIPType, Part};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
EAIPFetchError(reqwest::Error),
EAIPMissingPage(AIRAC, Part, EAIPType),
EAIPInvalidBaseURL(url::ParseError),
ChartURLMalformed(String),
CannotScrapeData(&'static str),
ParseError(&'static str, String),
}
impl std::error::Error for Error {}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::EAIPFetchError(e) => {
write!(f, "There was an error fetching data from the AIP: {:?}", e)
}
Self::EAIPMissingPage(airac, part, typ) => write!(
f,
"The AIP does not have a page for {} {} {}",
airac, part, typ
),
Self::EAIPInvalidBaseURL(e) => {
write!(f, "There was an error parsing the AIP base URL: {}", e)
}
Self::ChartURLMalformed(url) => {
write!(f, "There was an error convering the chart URL: {}", url)
}
Self::CannotScrapeData(reason) => {
write!(f, "The data cannot be scraped because {}", reason)
}
Self::ParseError(what, thing) => {
write!(f, "The {} cannot be parsed ({:?}).", what, thing)
}
}
}
}
impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Self {
Self::EAIPFetchError(e)
}
}