use fe2o3_amqp::link::ReceiverAttachError;
use fe2o3_amqp_management::error::AttachError;
use crate::{
amqp::error::{CbsAuthError, OpenReceiverError},
primitives::error::ClientDisposedError,
util::IntoAzureCoreError,
};
#[derive(Debug)]
pub struct SessionIdNotSet;
impl std::fmt::Display for SessionIdNotSet {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Session ID from the serivce is not set")
}
}
impl std::error::Error for SessionIdNotSet {}
impl From<SessionIdNotSet> for azure_core::Error {
fn from(value: SessionIdNotSet) -> Self {
azure_core::Error::new(azure_core::error::ErrorKind::Other, value)
}
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum AcceptNextSessionError {
#[error("The connection scope is disposed")]
ConnectionScopeDisposed,
#[error(transparent)]
ManagementLinkAttach(#[from] AttachError),
#[error(transparent)]
ReceiverAttach(#[from] ReceiverAttachError),
#[error(transparent)]
CbsAuth(#[from] CbsAuthError),
#[error("Session ID from the serivce is not set")]
SessionIdNotSet,
}
impl From<AcceptNextSessionError> for azure_core::Error {
fn from(value: AcceptNextSessionError) -> Self {
match value {
AcceptNextSessionError::ConnectionScopeDisposed => ClientDisposedError.into(),
AcceptNextSessionError::ManagementLinkAttach(error) => error.into_azure_core_error(),
AcceptNextSessionError::ReceiverAttach(error) => error.into_azure_core_error(),
AcceptNextSessionError::CbsAuth(error) => error.into(),
AcceptNextSessionError::SessionIdNotSet => SessionIdNotSet.into(),
}
}
}
impl From<OpenReceiverError> for AcceptNextSessionError {
fn from(error: OpenReceiverError) -> Self {
match error {
OpenReceiverError::ConnectionScopeDisposed => Self::ConnectionScopeDisposed,
OpenReceiverError::ManagementLinkAttach(error) => Self::ManagementLinkAttach(error),
OpenReceiverError::ReceiverAttach(error) => Self::ReceiverAttach(error),
OpenReceiverError::CbsAuth(error) => Self::CbsAuth(error),
}
}
}