1use std::fmt;
2use std::error::Error as StdError;
3use std::borrow::Cow;
4
5pub use stream::error::RequestError;
6
7
8pub trait ApiError: StdError {
11 fn from_request_error(e: RequestError) -> Self;
12
13 fn from_message_error(e: MessageError) -> Self;
14}
15
16
17#[derive(Debug)]
18#[non_exhaustive]
19pub enum Error {
20 MessageError(MessageError)
21}
22
23impl From<MessageError> for Error {
24 fn from(e: MessageError) -> Self {
25 Self::MessageError(e)
26 }
27}
28
29impl fmt::Display for Error {
30 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
31 fmt::Debug::fmt(self, fmt)
32 }
33}
34
35impl StdError for Error {}
36
37#[derive(Debug)]
38#[non_exhaustive]
39pub enum MessageError {
40 #[cfg(feature = "json")]
41 Json(serde_json::Error),
42 #[cfg(feature = "protobuf")]
44 EncodeError(fire_protobuf::encode::EncodeError),
45 #[cfg(feature = "protobuf")]
46 DecodeError(fire_protobuf::decode::DecodeError),
47 Other(Cow<'static, str>)
48}
49
50impl fmt::Display for MessageError {
51 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
52 fmt::Debug::fmt(self, fmt)
53 }
54}
55
56impl StdError for MessageError {}