ntex_amqp/server/
error.rs1use ntex_util::future::Either;
2
3use crate::codec::{AmqpCodecError, AmqpFrame, ProtocolIdError, SaslFrame, protocol};
4use crate::error::{AmqpDispatcherError, AmqpProtocolError};
5
6#[derive(Debug, thiserror::Error)]
8pub enum ServerError<E> {
9 #[error("Message handler service error")]
10 Service(E),
12 #[error("Handshake error: {}", 0)]
13 Handshake(HandshakeError),
15 #[error("Amqp codec error: {:?}", 0)]
17 Codec(AmqpCodecError),
18 #[error("Amqp protocol error: {:?}", 0)]
20 Protocol(AmqpProtocolError),
21 #[error("Amqp dispatcher error: {:?}", 0)]
23 Dispatcher(AmqpDispatcherError),
24 #[error("Control service init error")]
26 ControlServiceError,
27 #[error("Publish service init error")]
29 PublishServiceError,
30}
31
32impl<E> From<AmqpCodecError> for ServerError<E> {
33 fn from(err: AmqpCodecError) -> Self {
34 ServerError::Codec(err)
35 }
36}
37
38impl<E> From<AmqpProtocolError> for ServerError<E> {
39 fn from(err: AmqpProtocolError) -> Self {
40 ServerError::Protocol(err)
41 }
42}
43
44impl<E> From<HandshakeError> for ServerError<E> {
45 fn from(err: HandshakeError) -> Self {
46 ServerError::Handshake(err)
47 }
48}
49
50#[derive(Debug, From, thiserror::Error)]
52pub enum HandshakeError {
53 #[error("Amqp codec error: {:?}", 0)]
55 Codec(AmqpCodecError),
56 #[error("Handshake timeout")]
58 Timeout,
59 #[error("Peer disconnected")]
61 ProtocolNegotiation(ProtocolIdError),
62 #[from(ignore)]
63 #[error("Expect open frame, got: {:?}", 0)]
65 ExpectOpenFrame(AmqpFrame),
66 #[error("Unexpected frame, got: {:?}", 0)]
67 Unexpected(protocol::Frame),
68 #[error("Unexpected sasl frame: {:?}", 0)]
69 UnexpectedSaslFrame(Box<SaslFrame>),
70 #[error("Unexpected sasl frame body: {:?}", 0)]
71 UnexpectedSaslBodyFrame(Box<protocol::SaslFrameBody>),
72 #[error("Unsupported sasl mechanism: {}", 0)]
73 UnsupportedSaslMechanism(String),
74 #[error("Sasl error code: {:?}", 0)]
76 Sasl(protocol::SaslCode),
77 #[error("Peer disconnected, with error {:?}", 0)]
79 Disconnected(Option<std::io::Error>),
80}
81
82impl From<Either<AmqpCodecError, std::io::Error>> for HandshakeError {
83 fn from(err: Either<AmqpCodecError, std::io::Error>) -> Self {
84 match err {
85 Either::Left(err) => HandshakeError::Codec(err),
86 Either::Right(err) => HandshakeError::Disconnected(Some(err)),
87 }
88 }
89}
90
91impl From<Either<ProtocolIdError, std::io::Error>> for HandshakeError {
92 fn from(err: Either<ProtocolIdError, std::io::Error>) -> Self {
93 match err {
94 Either::Left(err) => HandshakeError::ProtocolNegotiation(err),
95 Either::Right(err) => HandshakeError::Disconnected(Some(err)),
96 }
97 }
98}