1use crate::auth::AuthError;
2use crate::grid::{Grid, ParseJsonGridError};
3use thiserror::Error;
4
5impl Error {
6 pub fn is_grid(&self) -> bool {
8 matches!(self, Self::Grid { .. })
9 }
10
11 pub fn grid(&self) -> Option<&Grid> {
14 match self {
15 Self::Grid { err_grid } => Some(err_grid),
16 _ => None,
17 }
18 }
19
20 pub fn into_grid(self) -> Option<Grid> {
23 match self {
24 Self::Grid { err_grid } => Some(err_grid),
25 _ => None,
26 }
27 }
28}
29
30#[derive(Debug, Error)]
32pub enum Error {
33 #[error("Server returned an error grid")]
35 Grid {
36 err_grid: Grid,
38 },
39 #[error("Error occurred in the underlying HTTP library")]
41 Http {
42 #[from]
43 err: reqwest::Error,
44 },
45 #[error("Could not parse JSON as a Haystack grid")]
47 ParseJsonGrid(#[from] ParseJsonGridError),
48 #[error("Not a valid time zone: {err_time_zone}")]
50 TimeZone {
51 err_time_zone: String,
53 },
54 #[error("Could not obtain a new auth token from the server")]
57 UpdateAuthToken(#[from] crate::auth::AuthError),
58}
59
60#[derive(Debug, Error)]
62pub enum NewSkySparkClientError {
63 #[error("Error occurred during authentication")]
65 Auth(#[from] AuthError),
66 #[error("The SkySpark URL is invalid: {msg}")]
68 Url { msg: String },
69}
70
71impl NewSkySparkClientError {
72 pub(crate) fn url(msg: &str) -> Self {
73 NewSkySparkClientError::Url { msg: msg.into() }
74 }
75}