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