gb28181/session/
errors.rs

1use {
2    bytesio::bytes_errors::BytesReadError,
3    bytesio::{bytes_errors::BytesWriteError, bytesio_errors::BytesIOError},
4    failure::{Backtrace, Fail},
5    std::fmt,
6    std::str::Utf8Error,
7};
8
9#[derive(Debug)]
10pub struct SessionError {
11    pub value: SessionErrorValue,
12}
13
14#[derive(Debug, Fail)]
15pub enum SessionErrorValue {
16    #[fail(display = "net io error: {}\n", _0)]
17    BytesIOError(#[cause] BytesIOError),
18    #[fail(display = "bytes read error: {}\n", _0)]
19    BytesReadError(#[cause] BytesReadError),
20    #[fail(display = "bytes write error: {}\n", _0)]
21    BytesWriteError(#[cause] BytesWriteError),
22    #[fail(display = "Utf8Error: {}\n", _0)]
23    Utf8Error(#[cause] Utf8Error),
24
25    #[fail(display = "stream hub event send error\n")]
26    StreamHubEventSendErr,
27    #[fail(display = "cannot receive frame data from stream hub\n")]
28    CannotReceiveFrameData,
29}
30
31impl From<BytesIOError> for SessionError {
32    fn from(error: BytesIOError) -> Self {
33        SessionError {
34            value: SessionErrorValue::BytesIOError(error),
35        }
36    }
37}
38
39impl From<BytesReadError> for SessionError {
40    fn from(error: BytesReadError) -> Self {
41        SessionError {
42            value: SessionErrorValue::BytesReadError(error),
43        }
44    }
45}
46
47impl From<BytesWriteError> for SessionError {
48    fn from(error: BytesWriteError) -> Self {
49        SessionError {
50            value: SessionErrorValue::BytesWriteError(error),
51        }
52    }
53}
54
55impl From<Utf8Error> for SessionError {
56    fn from(error: Utf8Error) -> Self {
57        SessionError {
58            value: SessionErrorValue::Utf8Error(error),
59        }
60    }
61}
62
63impl fmt::Display for SessionError {
64    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65        fmt::Display::fmt(&self.value, f)
66    }
67}
68
69impl Fail for SessionError {
70    fn cause(&self) -> Option<&dyn Fail> {
71        self.value.cause()
72    }
73
74    fn backtrace(&self) -> Option<&Backtrace> {
75        self.value.backtrace()
76    }
77}