use snafu::Snafu;
use crate::errors::sealed::Sealed;
pub mod session;
#[cfg(feature = "sso")]
pub mod sso;
#[cfg(feature = "mycqu")]
pub mod mycqu;
#[cfg(feature = "card")]
pub mod card;
mod sealed {
use crate::errors::sso;
pub trait Sealed {}
#[cfg(feature = "sso")]
impl Sealed for sso::SSOError {}
#[cfg(feature = "mycqu")]
impl Sealed for crate::errors::mycqu::MyCQUError {}
#[cfg(feature = "card")]
impl Sealed for card::CardError {}
}
pub trait RsMyCQUError: std::error::Error + 'static + Sealed {}
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum ApiError<T: RsMyCQUError> {
#[snafu(display("Request Before Login"))]
NotLogin,
#[snafu(display("Request Before Get Access"))]
NotAccess,
#[snafu(display("Reqwest Error: {source}"))]
Request {
source: reqwest::Error,
},
#[snafu(display("Model Parse Error: {msg}"))]
ModelParse {
msg: String,
},
#[snafu(display("Request Website Error: {msg}"))]
Website {
msg: String,
},
#[snafu(transparent)]
Inner {
source: T,
},
#[snafu(whatever)]
Whatever {
message: String,
#[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, Some)))]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
}
#[allow(private_bounds)]
impl<T: RsMyCQUError> ApiError<T> {
pub(crate) fn location_error() -> Self {
ApiError::Website {
msg: "Expected response has \"Location\" but not found".to_string(),
}
}
}
impl<T: RsMyCQUError> From<reqwest::Error> for ApiError<T> {
fn from(source: reqwest::Error) -> Self {
ApiError::Request { source }
}
}
pub type ApiResult<T, E> = Result<T, ApiError<E>>;