xref: /xiu/protocol/httpflv/src/errors.rs (revision a4ef5d6c)
1 use streamhub::errors::ChannelError;
2 
3 use {
4     failure::Fail,
5     futures::channel::mpsc::SendError,
6     rtmp::{
7         amf0::errors::Amf0WriteError, cache::errors::MetadataError, session::errors::SessionError,
8     },
9     std::fmt,
10     tokio::sync::oneshot::error::RecvError,
11     xflv::errors::FlvMuxerError,
12 };
13 
14 #[derive(Debug)]
15 pub struct ServerError {
16     pub value: ServerErrorValue,
17 }
18 
19 #[derive(Debug, Fail)]
20 pub enum ServerErrorValue {
21     #[fail(display = "server error")]
22     Error,
23 }
24 
25 pub struct HttpFLvError {
26     pub value: HttpFLvErrorValue,
27 }
28 
29 #[derive(Debug, Fail)]
30 pub enum HttpFLvErrorValue {
31     #[fail(display = "server error")]
32     Error,
33     #[fail(display = "session error")]
34     SessionError(SessionError),
35     #[fail(display = "flv muxer error")]
36     MuxerError(FlvMuxerError),
37     #[fail(display = "amf write error")]
38     Amf0WriteError(Amf0WriteError),
39     #[fail(display = "metadata error")]
40     MetadataError(MetadataError),
41     #[fail(display = "tokio mpsc error")]
42     MpscSendError(SendError),
43     #[fail(display = "event execute error: {}", _0)]
44     ChannelError(ChannelError),
45     #[fail(display = "tokio: oneshot receiver err: {}", _0)]
46     RecvError(#[cause] RecvError),
47     #[fail(display = "channel recv error")]
48     ChannelRecvError,
49 }
50 
51 impl From<SessionError> for HttpFLvError {
from(error: SessionError) -> Self52     fn from(error: SessionError) -> Self {
53         HttpFLvError {
54             value: HttpFLvErrorValue::SessionError(error),
55         }
56     }
57 }
58 
59 impl From<FlvMuxerError> for HttpFLvError {
from(error: FlvMuxerError) -> Self60     fn from(error: FlvMuxerError) -> Self {
61         HttpFLvError {
62             value: HttpFLvErrorValue::MuxerError(error),
63         }
64     }
65 }
66 
67 impl From<SendError> for HttpFLvError {
from(error: SendError) -> Self68     fn from(error: SendError) -> Self {
69         HttpFLvError {
70             value: HttpFLvErrorValue::MpscSendError(error),
71         }
72     }
73 }
74 
75 impl From<Amf0WriteError> for HttpFLvError {
from(error: Amf0WriteError) -> Self76     fn from(error: Amf0WriteError) -> Self {
77         HttpFLvError {
78             value: HttpFLvErrorValue::Amf0WriteError(error),
79         }
80     }
81 }
82 
83 impl From<MetadataError> for HttpFLvError {
from(error: MetadataError) -> Self84     fn from(error: MetadataError) -> Self {
85         HttpFLvError {
86             value: HttpFLvErrorValue::MetadataError(error),
87         }
88     }
89 }
90 
91 impl From<ChannelError> for HttpFLvError {
from(error: ChannelError) -> Self92     fn from(error: ChannelError) -> Self {
93         HttpFLvError {
94             value: HttpFLvErrorValue::ChannelError(error),
95         }
96     }
97 }
98 
99 impl From<RecvError> for HttpFLvError {
from(error: RecvError) -> Self100     fn from(error: RecvError) -> Self {
101         HttpFLvError {
102             value: HttpFLvErrorValue::RecvError(error),
103         }
104     }
105 }
106 
107 impl fmt::Display for HttpFLvError {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result108     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
109         fmt::Display::fmt(&self.value, f)
110     }
111 }
112