use crate::auth::AuthError;
use crate::grid::{Grid, ParseJsonGridError};
use thiserror::Error;
impl Error {
pub fn is_grid(&self) -> bool {
matches!(self, Self::Grid { .. })
}
pub fn grid(&self) -> Option<&Grid> {
match self {
Self::Grid { err_grid } => Some(err_grid),
_ => None,
}
}
pub fn into_grid(self) -> Option<Grid> {
match self {
Self::Grid { err_grid } => Some(err_grid),
_ => None,
}
}
}
#[derive(Debug, Error)]
pub enum Error {
#[error("Server returned an error grid")]
Grid {
err_grid: Grid,
},
#[error("Error occurred in the underlying HTTP library")]
Http {
#[from]
err: reqwest::Error,
},
#[error("Could not parse JSON as a Haystack grid")]
ParseJsonGrid(#[from] ParseJsonGridError),
#[error("Not a valid time zone: {err_time_zone}")]
TimeZone {
err_time_zone: String,
},
#[error("Could not obtain a new auth token from the server")]
UpdateAuthToken(#[from] crate::auth::AuthError),
}
#[derive(Debug, Error)]
pub enum NewSkySparkClientError {
#[error("Error occurred during authentication")]
Auth(#[from] AuthError),
#[error("The SkySpark URL is invalid: {msg}")]
Url { msg: String },
}
impl NewSkySparkClientError {
pub(crate) fn url(msg: &str) -> Self {
NewSkySparkClientError::Url { msg: msg.into() }
}
}
#[derive(Debug, Error)]
#[error("Could not create a new client seed")]
pub struct NewClientSeedError(#[from] reqwest::Error);