ruststream_lapin/
error.rs1use std::error::Error as StdError;
4use std::time::Duration;
5
6use thiserror::Error;
7
8#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum AmqpError {
15 #[error("amqp connection error: {0}")]
17 Connect(#[source] Box<dyn StdError + Send + Sync>),
18
19 #[error("amqp publish error: {0}")]
21 Publish(#[source] Box<dyn StdError + Send + Sync>),
22
23 #[error("amqp subscribe error: {0}")]
25 Subscribe(#[source] Box<dyn StdError + Send + Sync>),
26
27 #[error("amqp consume error: {0}")]
29 Consume(#[source] Box<dyn StdError + Send + Sync>),
30
31 #[error("amqp topology declaration error: {0}")]
33 Declare(#[source] Box<dyn StdError + Send + Sync>),
34
35 #[error("amqp request error: {0}")]
37 Request(#[source] Box<dyn StdError + Send + Sync>),
38
39 #[error("amqp request timed out after {0:?} without a reply")]
43 RequestTimeout(Duration),
44
45 #[error("amqp broker is not connected; `Broker::connect` must complete first")]
51 NotConnected,
52
53 #[error("invalid options: {0}")]
57 InvalidOptions(String),
58}
59
60impl AmqpError {
61 pub(crate) fn connect(err: lapin::Error) -> Self {
62 Self::Connect(Box::new(err))
63 }
64
65 pub(crate) fn publish(err: lapin::Error) -> Self {
66 Self::Publish(Box::new(err))
67 }
68
69 pub(crate) fn subscribe(err: lapin::Error) -> Self {
70 Self::Subscribe(Box::new(err))
71 }
72
73 pub(crate) fn consume(err: lapin::Error) -> Self {
74 Self::Consume(Box::new(err))
75 }
76
77 pub(crate) fn declare(err: lapin::Error) -> Self {
78 Self::Declare(Box::new(err))
79 }
80
81 pub(crate) fn request(err: lapin::Error) -> Self {
82 Self::Request(Box::new(err))
83 }
84}