xref: /xiu/protocol/webrtc/src/session/errors.rs (revision a4ef5d6c)
1 use streamhub::errors::ChannelError;
2 use {
3     bytesio::bytes_errors::BytesReadError,
4     bytesio::{bytes_errors::BytesWriteError, bytesio_errors::BytesIOError},
5     failure::{Backtrace, Fail},
6     std::fmt,
7     std::str::Utf8Error,
8     tokio::sync::oneshot::error::RecvError,
9     webrtc::error::Error as RTCError,
10 };
11 
12 #[derive(Debug)]
13 pub struct SessionError {
14     pub value: SessionErrorValue,
15 }
16 
17 #[derive(Debug, Fail)]
18 pub enum SessionErrorValue {
19     #[fail(display = "net io error: {}", _0)]
20     BytesIOError(#[cause] BytesIOError),
21     #[fail(display = "bytes read error: {}", _0)]
22     BytesReadError(#[cause] BytesReadError),
23     #[fail(display = "bytes write error: {}", _0)]
24     BytesWriteError(#[cause] BytesWriteError),
25     #[fail(display = "Utf8Error: {}", _0)]
26     Utf8Error(#[cause] Utf8Error),
27     #[fail(display = "event execute error: {}", _0)]
28     ChannelError(#[cause] ChannelError),
29     #[fail(display = "webrtc error: {}", _0)]
30     RTCError(#[cause] RTCError),
31     #[fail(display = "tokio: oneshot receiver err: {}", _0)]
32     RecvError(#[cause] RecvError),
33     #[fail(display = "stream hub event send error")]
34     StreamHubEventSendErr,
35     #[fail(display = "cannot receive frame data from stream hub")]
36     CannotReceiveFrameData,
37     #[fail(display = "Http Request path error")]
38     HttpRequestPathError,
39     #[fail(display = "Not supported")]
40     HttpRequestNotSupported,
41     #[fail(display = "Empty sdp data")]
42     HttpRequestEmptySdp,
43     #[fail(display = "Cannot find Content-Length")]
44     HttpRequestNoContentLength,
45     #[fail(display = "Channel receive error")]
46     ChannelRecvError,
47 }
48 
49 impl From<RTCError> for SessionError {
from(error: RTCError) -> Self50     fn from(error: RTCError) -> Self {
51         SessionError {
52             value: SessionErrorValue::RTCError(error),
53         }
54     }
55 }
56 
57 impl From<BytesIOError> for SessionError {
from(error: BytesIOError) -> Self58     fn from(error: BytesIOError) -> Self {
59         SessionError {
60             value: SessionErrorValue::BytesIOError(error),
61         }
62     }
63 }
64 
65 impl From<BytesReadError> for SessionError {
from(error: BytesReadError) -> Self66     fn from(error: BytesReadError) -> Self {
67         SessionError {
68             value: SessionErrorValue::BytesReadError(error),
69         }
70     }
71 }
72 
73 impl From<BytesWriteError> for SessionError {
from(error: BytesWriteError) -> Self74     fn from(error: BytesWriteError) -> Self {
75         SessionError {
76             value: SessionErrorValue::BytesWriteError(error),
77         }
78     }
79 }
80 
81 impl From<Utf8Error> for SessionError {
from(error: Utf8Error) -> Self82     fn from(error: Utf8Error) -> Self {
83         SessionError {
84             value: SessionErrorValue::Utf8Error(error),
85         }
86     }
87 }
88 
89 impl From<ChannelError> for SessionError {
from(error: ChannelError) -> Self90     fn from(error: ChannelError) -> Self {
91         SessionError {
92             value: SessionErrorValue::ChannelError(error),
93         }
94     }
95 }
96 
97 impl From<RecvError> for SessionError {
from(error: RecvError) -> Self98     fn from(error: RecvError) -> Self {
99         SessionError {
100             value: SessionErrorValue::RecvError(error),
101         }
102     }
103 }
104 
105 impl fmt::Display for SessionError {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result106     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
107         fmt::Display::fmt(&self.value, f)
108     }
109 }
110 
111 impl Fail for SessionError {
cause(&self) -> Option<&dyn Fail>112     fn cause(&self) -> Option<&dyn Fail> {
113         self.value.cause()
114     }
115 
backtrace(&self) -> Option<&Backtrace>116     fn backtrace(&self) -> Option<&Backtrace> {
117         self.value.backtrace()
118     }
119 }
120