1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::auth::AuthError;
use crate::grid::{Grid, ParseJsonGridError};
use thiserror::Error;
impl Error {
/// Return true if this error encapsulates a Haystack error grid.
pub fn is_grid(&self) -> bool {
matches!(self, Self::Grid { .. })
}
/// Return a reference to the Haystack error grid encapsulated by this
/// error, if this error was caused by a Haystack error grid.
pub fn grid(&self) -> Option<&Grid> {
match self {
Self::Grid { err_grid } => Some(err_grid),
_ => None,
}
}
/// Return the Haystack error grid encapsulated by this error, if this
/// error was caused by a Haystack error grid.
pub fn into_grid(self) -> Option<Grid> {
match self {
Self::Grid { err_grid } => Some(err_grid),
_ => None,
}
}
}
/// Describes the kinds of errors that can occur in this crate.
#[derive(Debug, Error)]
pub enum Error {
/// The grid contained error information from the server.
#[error("Server returned an error grid")]
Grid {
/// The grid which caused this error.
err_grid: Grid,
},
/// An error which originated from the underlying HTTP library.
#[error("Error occurred in the underlying HTTP library")]
Http {
#[from]
err: reqwest::Error,
},
/// An error related to parsing a `Grid` from a JSON value.
#[error("Could not parse JSON as a Haystack grid")]
ParseJsonGrid(#[from] ParseJsonGridError),
/// An error caused by an invalid time zone.
#[error("Not a valid time zone: {err_time_zone}")]
TimeZone {
/// The time zone which caused the error.
err_time_zone: String,
},
/// An error occurred when trying to obtain a new auth token from
/// the server.
#[error("Could not obtain a new auth token from the server")]
UpdateAuthToken(#[from] crate::auth::AuthError),
}
/// Errors that can occur when creating a new `SkySparkClient`.
#[derive(Debug, Error)]
pub enum NewSkySparkClientError {
/// An error which occurred during the authentication process.
#[error("Error occurred during authentication")]
Auth(#[from] AuthError),
/// An error caused by an invalid SkySpark project url.
#[error("The SkySpark URL is invalid: {msg}")]
Url { msg: String },
}
impl NewSkySparkClientError {
pub(crate) fn url(msg: &str) -> Self {
NewSkySparkClientError::Url { msg: msg.into() }
}
}