1#[derive(thiserror::Error, Debug)]
3pub enum SessionError {
4 #[error("no error")]
6 NoError,
7
8 #[error("internal error")]
9 InternalError,
10
11 #[error("unauthorized")]
12 Unauthorized,
13
14 #[error("protocol violation")]
15 ProtocolViolation,
16
17 #[error("duplicate track alias")]
18 DuplicateTrackAlias,
19
20 #[error("parameter length mismatch")]
21 ParameterLengthMismatch,
22
23 #[error("too many subscribes")]
24 TooManySubscribes,
25
26 #[error("goaway timeout")]
27 GoawayTimeout,
28
29 #[error("unknown error: code={0}")]
30 Unknown(u64),
31 }
33
34pub trait MoqError {
35 fn code(&self) -> u64;
37}
38
39impl MoqError for SessionError {
40 fn code(&self) -> u64 {
42 match self {
43 Self::NoError => 0x0,
45 Self::InternalError => 0x1,
46 Self::Unauthorized => 0x2,
47 Self::ProtocolViolation => 0x3,
48 Self::DuplicateTrackAlias => 0x4,
49 Self::ParameterLengthMismatch => 0x5,
50 Self::TooManySubscribes => 0x6,
51 Self::GoawayTimeout => 0x10,
52 Self::Unknown(code) => *code,
53 }
55 }
56}
57
58#[derive(thiserror::Error, Debug)]
60pub enum SubscribeError {
61 #[error("internal error")]
63 InternalError,
64
65 #[error("invalid range")]
66 InvalidRange,
67
68 #[error("retry track alias")]
69 RetryTrackAlias,
70
71 #[error("track does not exist")]
72 TrackDoesNotExist,
73
74 #[error("unauthorized")]
75 Unauthorized,
76
77 #[error("timeout")]
78 Timeout,
79
80 #[error("unknown error: code={0}")]
81 Unknown(u64),
82 }
84
85impl MoqError for SubscribeError {
86 fn code(&self) -> u64 {
88 match self {
89 Self::InternalError => 0x0,
91 Self::InvalidRange => 0x1,
92 Self::RetryTrackAlias => 0x2,
93 Self::TrackDoesNotExist => 0x3,
94 Self::Unauthorized => 0x4,
95 Self::Timeout => 0x5,
96 Self::Unknown(code) => *code,
97 }
99 }
100}
101
102#[derive(thiserror::Error, Debug)]
104pub enum SubscribeDone {
105 #[error("unsubscribed")]
107 Unsubscribed,
108
109 #[error("internal error")]
110 InternalError,
111
112 #[error("unauthorized")]
114 Unauthorized,
115
116 #[error("track ended")]
117 TrackEnded,
118
119 #[error("subscription ended")]
121 SubscriptionEnded,
122
123 #[error("going away")]
124 GoingAway,
125
126 #[error("expired")]
127 Expired,
128
129 #[error("unknown error: code={0}")]
130 Unknown(u64),
131}
132
133impl From<u64> for SubscribeDone {
134 fn from(code: u64) -> Self {
135 match code {
136 0x0 => Self::Unsubscribed,
137 0x1 => Self::InternalError,
138 0x2 => Self::Unauthorized,
139 0x3 => Self::TrackEnded,
140 0x4 => Self::SubscriptionEnded,
141 0x5 => Self::GoingAway,
142 0x6 => Self::Expired,
143 _ => Self::Unknown(code),
144 }
145 }
146}
147
148impl MoqError for SubscribeDone {
149 fn code(&self) -> u64 {
151 match self {
152 Self::Unsubscribed => 0x0,
154 Self::InternalError => 0x1,
155 Self::Unauthorized => 0x2,
156 Self::TrackEnded => 0x3,
157 Self::SubscriptionEnded => 0x4,
158 Self::GoingAway => 0x5,
159 Self::Expired => 0x6,
160 Self::Unknown(code) => *code,
161 }
163 }
164}