notifica_rust_sdk/
error.rs1#[derive(Debug, thiserror::Error)]
3pub enum NotificaError {
4 #[error("HTTP request failed: {0}")]
6 Http(#[from] reqwest::Error),
7
8 #[error("serialization error: {0}")]
10 Serialization(#[from] serde_json::Error),
11
12 #[error("notifica service returned unexpected status {status}: {body}")]
14 UnexpectedResponse { status: u16, body: String },
15
16 #[error("client configuration error: {0}")]
18 Configuration(String),
19
20 #[cfg(feature = "queue")]
22 #[error("queue error: {0}")]
23 Queue(String),
24}
25
26pub type NotificaResult<T> = Result<T, NotificaError>;
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn unexpected_response_formats_correctly() {
35 let err = NotificaError::UnexpectedResponse {
36 status: 404,
37 body: "not found".into(),
38 };
39 assert_eq!(
40 err.to_string(),
41 "notifica service returned unexpected status 404: not found"
42 );
43 }
44
45 #[test]
46 fn configuration_error_formats_correctly() {
47 let err = NotificaError::Configuration("base_url is empty".into());
48 assert_eq!(
49 err.to_string(),
50 "client configuration error: base_url is empty"
51 );
52 }
53}