1use thiserror::Error;
2
3#[derive(Debug, Clone, Error)]
5#[non_exhaustive]
6pub enum CamelError {
7 #[error("Component not found: {0}")]
8 ComponentNotFound(String),
9
10 #[error("Endpoint creation failed: {0}")]
11 EndpointCreationFailed(String),
12
13 #[error("Processor error: {0}")]
14 ProcessorError(String),
15
16 #[error("Type conversion failed: {0}")]
17 TypeConversionFailed(String),
18
19 #[error("Invalid URI: {0}")]
20 InvalidUri(String),
21
22 #[error("Channel closed")]
23 ChannelClosed,
24
25 #[error("Route error: {0}")]
26 RouteError(String),
27
28 #[error("IO error: {0}")]
29 Io(String),
30
31 #[error("Dead letter channel failed: {0}")]
32 DeadLetterChannelFailed(String),
33
34 #[error("Circuit breaker open: {0}")]
35 CircuitOpen(String),
36
37 #[error("HTTP operation failed: {status_code} {status_text}")]
38 HttpOperationFailed {
39 status_code: u16,
40 status_text: String,
41 response_body: Option<String>,
42 },
43
44 #[error("Exchange stopped by Stop EIP")]
45 Stopped,
46
47 #[error("Configuration error: {0}")]
48 Config(String),
49}
50
51impl From<std::io::Error> for CamelError {
52 fn from(err: std::io::Error) -> Self {
53 CamelError::Io(err.to_string())
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_http_operation_failed_display() {
63 let err = CamelError::HttpOperationFailed {
64 status_code: 404,
65 status_text: "Not Found".to_string(),
66 response_body: Some("page not found".to_string()),
67 };
68 let msg = format!("{err}");
69 assert!(msg.contains("404"));
70 assert!(msg.contains("Not Found"));
71 }
72
73 #[test]
74 fn test_http_operation_failed_clone() {
75 let err = CamelError::HttpOperationFailed {
76 status_code: 500,
77 status_text: "Internal Server Error".to_string(),
78 response_body: None,
79 };
80 let cloned = err.clone();
81 assert!(matches!(
82 cloned,
83 CamelError::HttpOperationFailed {
84 status_code: 500,
85 ..
86 }
87 ));
88 }
89
90 #[test]
91 fn test_stopped_variant_exists_and_is_clone() {
92 let err = CamelError::Stopped;
93 let cloned = err.clone();
94 assert!(matches!(cloned, CamelError::Stopped));
95 assert_eq!(format!("{err}"), "Exchange stopped by Stop EIP");
96 }
97}