use serde_json;
use ureq;
#[cfg(feature = "fantasy")]
use serde_yaml;
use crate::jolpica::response::{Payload, Table};
#[cfg(doc)]
use crate::jolpica::{
concat::PageVerify,
resource::Resource,
response::{self, Response},
};
#[derive(Debug)]
pub enum Error {
Http(ureq::Error),
Io(std::io::Error),
Parse(serde_json::Error),
#[cfg(feature = "fantasy")]
YamlParse(serde_yaml::Error),
HttpRetries((usize , ureq::Error)),
MultiPage,
BadTableVariant,
BadPayloadVariant,
NotFound,
TooMany,
ExceededMaxPageCount((usize , usize )),
BadResponseInfo(String),
BadPagination(String),
EmptyResponseList,
UnexpectedData(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
impl std::error::Error for Error {}
impl From<ureq::Error> for Error {
fn from(error: ureq::Error) -> Self {
Self::Http(error)
}
}
impl From<std::io::Error> for Error {
fn from(error: std::io::Error) -> Self {
Self::Io(error)
}
}
impl From<serde_json::Error> for Error {
fn from(error: serde_json::Error) -> Self {
Self::Parse(error)
}
}
#[cfg(feature = "fantasy")]
impl From<serde_yaml::Error> for Error {
fn from(error: serde_yaml::Error) -> Self {
Self::YamlParse(error)
}
}
impl From<Table> for Error {
fn from(_: Table) -> Self {
Self::BadTableVariant
}
}
impl From<Payload> for Error {
fn from(_: Payload) -> Self {
Self::BadPayloadVariant
}
}
pub type Result<T> = std::result::Result<T, Error>;