xref: /xiu/protocol/webrtc/src/errors.rs (revision 69de9bbd)
1 use {
2     failure::{Backtrace, Fail},
3     std::fmt,
4     webrtc::error::Error as RTCError,
5     webrtc::util::Error as RTCUtilError,
6 };
7 
8 #[derive(Debug)]
9 pub struct WebRTCError {
10     pub value: WebRTCErrorValue,
11 }
12 
13 #[derive(Debug, Fail)]
14 pub enum WebRTCErrorValue {
15     #[fail(display = "webrtc error: {}", _0)]
16     RTCError(#[cause] RTCError),
17     #[fail(display = "webrtc util error: {}", _0)]
18     RTCUtilError(#[cause] RTCUtilError),
19     #[fail(display = "cannot get local description")]
20     CanNotGetLocalDescription,
21 }
22 
23 impl From<RTCError> for WebRTCError {
from(error: RTCError) -> Self24     fn from(error: RTCError) -> Self {
25         WebRTCError {
26             value: WebRTCErrorValue::RTCError(error),
27         }
28     }
29 }
30 
31 impl From<RTCUtilError> for WebRTCError {
from(error: RTCUtilError) -> Self32     fn from(error: RTCUtilError) -> Self {
33         WebRTCError {
34             value: WebRTCErrorValue::RTCUtilError(error),
35         }
36     }
37 }
38 
39 impl fmt::Display for WebRTCError {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result40     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41         fmt::Display::fmt(&self.value, f)
42     }
43 }
44 
45 impl Fail for WebRTCError {
cause(&self) -> Option<&dyn Fail>46     fn cause(&self) -> Option<&dyn Fail> {
47         self.value.cause()
48     }
49 
backtrace(&self) -> Option<&Backtrace>50     fn backtrace(&self) -> Option<&Backtrace> {
51         self.value.backtrace()
52     }
53 }
54