xref: /xiu/protocol/rtmp/src/relay/errors.rs (revision ea7993e4)
1 use {
2     failure::Fail,
3     std::{fmt, io::Error},
4     tokio::sync::broadcast::error::RecvError,
5 };
6 
7 #[derive(Debug)]
8 pub struct ClientError {
9     pub value: PushClientErrorValue,
10 }
11 
12 impl fmt::Display for ClientError {
13     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14         fmt::Display::fmt(&self.value, f)
15     }
16 }
17 
18 #[derive(Debug, Fail)]
19 pub enum PushClientErrorValue {
20     #[fail(display = "receive error\n")]
21     ReceiveError(RecvError),
22 
23     #[fail(display = "send error\n")]
24     SendError,
25     #[fail(display = "io error\n")]
26     IOError(Error),
27 }
28 
29 impl From<Error> for ClientError {
30     fn from(error: Error) -> Self {
31         ClientError {
32             value: PushClientErrorValue::IOError(error),
33         }
34     }
35 }
36 
37 impl From<RecvError> for ClientError {
38     fn from(error: RecvError) -> Self {
39         ClientError {
40             value: PushClientErrorValue::ReceiveError(error),
41         }
42     }
43 }
44