use thiserror::Error;
#[derive(Error,Debug)]
pub enum JWTError{
#[error("Failed to base64 encode the password hash")]
FailedToEncode(#[from] base64ct::InvalidLengthError),
#[error("Failed to base64 encode the password hash")]
FailedToHash(#[from] hmac::digest::InvalidLength)
}
#[derive(Error,Debug)]
pub enum APIRequestError{
#[error("Failed to fetch")]
FailedToFetch(#[from] reqwest::Error),
#[error("Api error")]
ApiError(#[from] APIError),
}
#[derive(Error,Debug)]
pub struct APIError{
pub msg: String
}
impl std::fmt::Display for APIError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f,"{}",self.msg)
}
}
#[derive(Error,Debug)]
pub struct SeasonParseStringError{
pub the_string: String
}
impl std::fmt::Display for SeasonParseStringError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f,"Could not parse Season from \"{}\" as it does not follow the format \"year_slot\" where slot equals either 1 or 2",self.the_string)
}
}
#[derive(Error,Debug)]
pub enum ApiCreationError{
#[error("Failed to create reqwest client")]
FailedToCreateClient(#[from] reqwest::Error),
#[error("Failed to create jwt")]
JWTFailed(#[from] JWTError),
}