highflame_shield/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum ShieldError {
8 #[error("[{status}] {title}: {detail}")]
10 Api {
11 status: u16,
13 title: String,
15 detail: String,
17 },
18
19 #[error("connection error: {0}")]
21 Connection(String),
22
23 #[error("deserialisation error: {0}")]
25 Deserialisation(#[from] serde_json::Error),
26}
27
28impl ShieldError {
29 pub fn status(&self) -> Option<u16> {
31 match self {
32 ShieldError::Api { status, .. } => Some(*status),
33 _ => None,
34 }
35 }
36
37 pub fn is_api_error(&self) -> bool {
39 matches!(self, ShieldError::Api { .. })
40 }
41
42 pub fn is_connection_error(&self) -> bool {
44 matches!(self, ShieldError::Connection(_))
45 }
46}
47
48impl From<reqwest::Error> for ShieldError {
49 fn from(e: reqwest::Error) -> Self {
50 ShieldError::Connection(e.to_string())
51 }
52}