agile_config_client/
error.rs1#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("app_id must not be empty")]
9 EmptyAppId,
10 #[error("at least one server node is required")]
12 EmptyNodes,
13 #[error("invalid server node URL: {0}")]
15 InvalidNode(String),
16 #[error("failed to load configuration from all nodes")]
18 LoadFailed,
19 #[error("HTTP {status} from {url}")]
21 HttpStatus {
22 url: String,
24 status: u16,
26 },
27 #[error(transparent)]
29 Request(#[from] reqwest::Error),
30 #[error("websocket error: {0}")]
32 WebSocket(String),
33 #[error("failed to parse configuration payload: {0}")]
35 Protocol(#[from] serde_json::Error),
36 #[error("cache error: {0}")]
38 Cache(String),
39 #[error("cache encryption requires the `cache-encrypt` cargo feature")]
42 CacheEncryptDisabled,
43}
44
45impl Error {
46 pub(crate) fn websocket<E: std::fmt::Display>(error: E) -> Self {
47 Self::WebSocket(error.to_string())
48 }
49
50 pub(crate) fn cache<E: std::fmt::Display>(error: E) -> Self {
51 Self::Cache(error.to_string())
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::Error;
58
59 #[test]
60 fn empty_app_id_displays_clear_message() {
61 assert_eq!(Error::EmptyAppId.to_string(), "app_id must not be empty");
62 }
63}