Skip to content

Commit

Permalink
error: add helper methods
Browse files Browse the repository at this point in the history
Will be used to check if error can be recovered on the channel or connection level

Signed-off-by: Marc-Antoine Perennou <[email protected]>
  • Loading branch information
Keruspe committed Jul 27, 2024
1 parent de150fb commit f11b069
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::{
channel_status::ChannelState, connection_status::ConnectionState, protocol::AMQPError,
types::ChannelId,
};
use amq_protocol::frame::{GenError, ParserError, ProtocolVersion};
use amq_protocol::{
frame::{GenError, ParserError, ProtocolVersion},
protocol::{AMQPErrorKind, AMQPSoftError},

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `AMQPSoftError`

warning: unused import: `AMQPSoftError` --> src/error.rs:7:31 | 7 | protocol::{AMQPErrorKind, AMQPSoftError}, | ^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, beta)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, beta)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, nightly)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, nightly)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, nightly)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, 1.74.0)

unused import: `AMQPSoftError`

Check warning on line 7 in src/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, 1.74.0)

unused import: `AMQPSoftError`
};
use std::{error, fmt, io, sync::Arc};

/// A std Result with a lapin::Error error type
Expand Down Expand Up @@ -49,6 +52,24 @@ impl Error {
false
}
}

pub fn is_amqp_soft_error(&self) -> bool {
if let Error::ProtocolError(e) = self {
if let AMQPErrorKind::Soft(_) = e.kind() {
return true;
}
}
false
}

pub fn is_amqp_hard_error(&self) -> bool {
if let Error::ProtocolError(e) = self {
if let AMQPErrorKind::Hard(_) = e.kind() {
return true;
}
}
false
}
}

impl fmt::Display for Error {
Expand Down

0 comments on commit f11b069

Please sign in to comment.