1use thiserror::Error;
2use tokio_tungstenite::tungstenite;
3
4pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug, Error)]
7pub enum Error {
8 #[error("vapour-protocol feature is not implemented yet: {0}")]
9 Unsupported(&'static str),
10 #[error("protocol error: {0}")]
11 Protocol(String),
12 #[error("authentication error: {0}")]
13 Authentication(String),
14 #[error("transport error: {0}")]
15 Transport(String),
16 #[error("unexpected websocket close")]
17 Closed,
18 #[error("invalid packet: {0}")]
19 InvalidPacket(&'static str),
20 #[error("missing field: {0}")]
21 MissingField(&'static str),
22 #[error("invalid response: {0}")]
23 InvalidResponse(&'static str),
24 #[error(transparent)]
25 Io(#[from] std::io::Error),
26 #[error(transparent)]
27 Http(#[from] reqwest::Error),
28 #[error(transparent)]
29 Json(#[from] serde_json::Error),
30 #[error(transparent)]
31 ProstDecode(#[from] prost::DecodeError),
32 #[error(transparent)]
33 ProstEncode(#[from] prost::EncodeError),
34 #[error(transparent)]
35 WebSocket(Box<tungstenite::Error>),
36}
37
38impl Error {
39 pub fn unsupported(feature: &'static str) -> Self {
40 Self::Unsupported(feature)
41 }
42}
43
44impl From<tungstenite::Error> for Error {
45 fn from(error: tungstenite::Error) -> Self {
46 Self::WebSocket(Box::new(error))
47 }
48}