mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 11:45:02 +01:00
improve errors
This commit is contained in:
parent
232c1d2830
commit
2be26f7e49
3 changed files with 68 additions and 10 deletions
|
|
@ -16,48 +16,105 @@ pub enum ProtocolError {
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum ConException {
|
pub enum ConException {
|
||||||
|
#[error("320 Connection forced")]
|
||||||
|
ConnectionForced,
|
||||||
|
#[error("402 Invalid path")]
|
||||||
|
InvalidPath,
|
||||||
#[error("501 Frame error")]
|
#[error("501 Frame error")]
|
||||||
FrameError,
|
FrameError,
|
||||||
#[error("503 Command invalid")]
|
#[error("502 Syntax error | {0:?}")]
|
||||||
CommandInvalid,
|
|
||||||
#[error("503 Syntax error | {0:?}")]
|
|
||||||
/// A method was received but there was a syntax error. The string stores where it occurred.
|
/// A method was received but there was a syntax error. The string stores where it occurred.
|
||||||
SyntaxError(Vec<String>),
|
SyntaxError(Vec<String>),
|
||||||
|
#[error("503 Command invalid")]
|
||||||
|
CommandInvalid,
|
||||||
#[error("504 Channel error")]
|
#[error("504 Channel error")]
|
||||||
ChannelError,
|
ChannelError,
|
||||||
#[error("505 Unexpected Frame")]
|
#[error("505 Unexpected Frame")]
|
||||||
UnexpectedFrame,
|
UnexpectedFrame,
|
||||||
|
#[error("506 Resource Error")]
|
||||||
|
ResourceError,
|
||||||
|
#[error("530 Not allowed")]
|
||||||
|
NotAllowed,
|
||||||
#[error("540 Not implemented. '{0}'")]
|
#[error("540 Not implemented. '{0}'")]
|
||||||
NotImplemented(&'static str),
|
NotImplemented(&'static str),
|
||||||
#[error("xxx Not decided yet")]
|
#[error("541 Internal error")]
|
||||||
|
InternalError,
|
||||||
|
#[error("xxx Todo")]
|
||||||
Todo,
|
Todo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConException {
|
impl ConException {
|
||||||
pub fn reply_code(&self) -> ReplyCode {
|
pub fn reply_code(&self) -> ReplyCode {
|
||||||
match self {
|
match self {
|
||||||
|
ConException::ConnectionForced => 320,
|
||||||
|
ConException::InvalidPath => 402,
|
||||||
ConException::FrameError => 501,
|
ConException::FrameError => 501,
|
||||||
ConException::CommandInvalid => 503,
|
ConException::CommandInvalid => 503,
|
||||||
ConException::SyntaxError(_) => 503,
|
ConException::SyntaxError(_) => 503,
|
||||||
ConException::ChannelError => 504,
|
ConException::ChannelError => 504,
|
||||||
ConException::UnexpectedFrame => 505,
|
ConException::UnexpectedFrame => 505,
|
||||||
|
ConException::ResourceError => 506,
|
||||||
|
ConException::NotAllowed => 530,
|
||||||
|
ConException::InternalError => 541,
|
||||||
ConException::NotImplemented(_) => 540,
|
ConException::NotImplemented(_) => 540,
|
||||||
ConException::Todo => 0,
|
ConException::Todo => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn reply_text(&self) -> ReplyText {
|
pub fn reply_text(&self) -> ReplyText {
|
||||||
"cant be bothered yet".to_string() // todo
|
match self {
|
||||||
|
ConException::ConnectionForced => "connection-forced",
|
||||||
|
ConException::InvalidPath => "invalid-path",
|
||||||
|
ConException::FrameError => "frame-error",
|
||||||
|
ConException::SyntaxError(_) => "syntax-error",
|
||||||
|
ConException::CommandInvalid => "command-invalid",
|
||||||
|
ConException::ChannelError => "channel-error",
|
||||||
|
ConException::UnexpectedFrame => "unexpected-frame",
|
||||||
|
ConException::ResourceError => "resource-error",
|
||||||
|
ConException::NotAllowed => "not-allowed",
|
||||||
|
ConException::NotImplemented(_) => "not-implemented",
|
||||||
|
ConException::InternalError => "internal-error",
|
||||||
|
ConException::Todo => "todo",
|
||||||
|
}
|
||||||
|
.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum ChannelException {}
|
pub enum ChannelException {
|
||||||
|
#[error("311 Content too large")]
|
||||||
|
ContentTooLarge,
|
||||||
|
#[error("313 No consumers")]
|
||||||
|
NoConsumers,
|
||||||
|
#[error("403 Access refused")]
|
||||||
|
AccessRefused,
|
||||||
|
#[error("404 Not found")]
|
||||||
|
NotFound,
|
||||||
|
#[error("405 Resource locked")]
|
||||||
|
ResourceLocked,
|
||||||
|
#[error("406 Precondition failed")]
|
||||||
|
PreconditionFailed,
|
||||||
|
}
|
||||||
|
|
||||||
impl ChannelException {
|
impl ChannelException {
|
||||||
pub fn reply_code(&self) -> ReplyCode {
|
pub fn reply_code(&self) -> ReplyCode {
|
||||||
todo!()
|
match self {
|
||||||
|
ChannelException::ContentTooLarge => 311,
|
||||||
|
ChannelException::NoConsumers => 313,
|
||||||
|
ChannelException::AccessRefused => 403,
|
||||||
|
ChannelException::NotFound => 404,
|
||||||
|
ChannelException::ResourceLocked => 405,
|
||||||
|
ChannelException::PreconditionFailed => 406,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn reply_text(&self) -> ReplyText {
|
pub fn reply_text(&self) -> ReplyText {
|
||||||
todo!()
|
match self {
|
||||||
|
ChannelException::ContentTooLarge => "content-too-large",
|
||||||
|
ChannelException::NoConsumers => "no-consumers",
|
||||||
|
ChannelException::AccessRefused => "access-refused",
|
||||||
|
ChannelException::NotFound => "not-found",
|
||||||
|
ChannelException::ResourceLocked => "resource-locked",
|
||||||
|
ChannelException::PreconditionFailed => "precondition-failed",
|
||||||
|
}
|
||||||
|
.to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ impl Connection {
|
||||||
/* do nothing, remove below */
|
/* do nothing, remove below */
|
||||||
}
|
}
|
||||||
Err(TransError::Protocol(ProtocolError::ConException(ex))) => {
|
Err(TransError::Protocol(ProtocolError::ConException(ex))) => {
|
||||||
warn!(%ex, "Connection exception occured. This indicates a faulty client.");
|
warn!(%ex, "Connection exception occurred. This indicates a faulty client.");
|
||||||
if let Err(err) = self
|
if let Err(err) = self
|
||||||
.send_method(
|
.send_method(
|
||||||
ChannelNum::zero(),
|
ChannelNum::zero(),
|
||||||
|
|
@ -262,6 +262,7 @@ impl Connection {
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(TransError::Protocol(ProtocolError::ChannelException(ex))) => {
|
Err(TransError::Protocol(ProtocolError::ChannelException(ex))) => {
|
||||||
|
warn!(%ex, "Channel exception occurred");
|
||||||
self.send_method(
|
self.send_method(
|
||||||
channel,
|
channel,
|
||||||
Method::ChannelClose(ChannelClose {
|
Method::ChannelClose(ChannelClose {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const connection = await connectAmqp();
|
||||||
|
|
||||||
const channel = await connection.createChannel();
|
const channel = await connection.createChannel();
|
||||||
|
|
||||||
const reply = await channel.assertQueue(queueName, { durable: true });
|
const reply = await channel.assertQueue(queueName, { durable: false });
|
||||||
|
|
||||||
assert(reply.messageCount === 0, 'Message found in queue');
|
assert(reply.messageCount === 0, 'Message found in queue');
|
||||||
assert(reply.consumerCount === 0, 'Consumer listening on queue');
|
assert(reply.consumerCount === 0, 'Consumer listening on queue');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue