#[derive(thiserror::Error, Debug)]
pub enum SessionError {
#[error("no error")]
NoError,
#[error("internal error")]
InternalError,
#[error("unauthorized")]
Unauthorized,
#[error("protocol violation")]
ProtocolViolation,
#[error("duplicate track alias")]
DuplicateTrackAlias,
#[error("parameter length mismatch")]
ParameterLengthMismatch,
#[error("too many subscribes")]
TooManySubscribes,
#[error("goaway timeout")]
GoawayTimeout,
#[error("unknown error: code={0}")]
Unknown(u64),
}
pub trait MoqError {
fn code(&self) -> u64;
}
impl MoqError for SessionError {
fn code(&self) -> u64 {
match self {
Self::NoError => 0x0,
Self::InternalError => 0x1,
Self::Unauthorized => 0x2,
Self::ProtocolViolation => 0x3,
Self::DuplicateTrackAlias => 0x4,
Self::ParameterLengthMismatch => 0x5,
Self::TooManySubscribes => 0x6,
Self::GoawayTimeout => 0x10,
Self::Unknown(code) => *code,
}
}
}
#[derive(thiserror::Error, Debug)]
pub enum SubscribeError {
#[error("internal error")]
InternalError,
#[error("invalid range")]
InvalidRange,
#[error("retry track alias")]
RetryTrackAlias,
#[error("track does not exist")]
TrackDoesNotExist,
#[error("unauthorized")]
Unauthorized,
#[error("timeout")]
Timeout,
#[error("unknown error: code={0}")]
Unknown(u64),
}
impl MoqError for SubscribeError {
fn code(&self) -> u64 {
match self {
Self::InternalError => 0x0,
Self::InvalidRange => 0x1,
Self::RetryTrackAlias => 0x2,
Self::TrackDoesNotExist => 0x3,
Self::Unauthorized => 0x4,
Self::Timeout => 0x5,
Self::Unknown(code) => *code,
}
}
}
#[derive(thiserror::Error, Debug)]
pub enum SubscribeDone {
#[error("unsubscribed")]
Unsubscribed,
#[error("internal error")]
InternalError,
#[error("unauthorized")]
Unauthorized,
#[error("track ended")]
TrackEnded,
#[error("subscription ended")]
SubscriptionEnded,
#[error("going away")]
GoingAway,
#[error("expired")]
Expired,
#[error("unknown error: code={0}")]
Unknown(u64),
}
impl From<u64> for SubscribeDone {
fn from(code: u64) -> Self {
match code {
0x0 => Self::Unsubscribed,
0x1 => Self::InternalError,
0x2 => Self::Unauthorized,
0x3 => Self::TrackEnded,
0x4 => Self::SubscriptionEnded,
0x5 => Self::GoingAway,
0x6 => Self::Expired,
_ => Self::Unknown(code),
}
}
}
impl MoqError for SubscribeDone {
fn code(&self) -> u64 {
match self {
Self::Unsubscribed => 0x0,
Self::InternalError => 0x1,
Self::Unauthorized => 0x2,
Self::TrackEnded => 0x3,
Self::SubscriptionEnded => 0x4,
Self::GoingAway => 0x5,
Self::Expired => 0x6,
Self::Unknown(code) => *code,
}
}
}