Skip to main content

phoenix_chan/
error.rs

1//! Errors returned by the client.
2
3use tungstenite::http;
4
5use crate::message::Message;
6
7type TungsteniteError = Box<tungstenite::Error>;
8
9/// Error returned by the [`Client`](crate::client::Client) or connection.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// Couldn't add headers to uri.
13    #[error("couldn't add the vsn header to uri")]
14    Uri(#[source] http::uri::InvalidUri),
15    /// Couldn't add headers to uri.
16    #[error("couldn't build the uri with the vsn version")]
17    UriBuild(#[source] http::Error),
18    /// Couldn't connect to the web-socket
19    #[error("couldn't connect to the web-socket")]
20    Connect(#[source] TungsteniteError),
21    /// Couldn't serialize message
22    #[error("couldn't serialize message")]
23    Serialize(#[source] serde_json::Error),
24    /// Couldn't de-serialize message
25    #[error("couldn't deserialize message")]
26    Deserialize(#[source] serde_json::Error),
27    /// Couldn't send a message
28    #[error("couldn't send message {msg}")]
29    Send {
30        /// The message that was sent
31        msg: Message<()>,
32        #[source]
33        /// Backtrace error
34        backtrace: TungsteniteError,
35    },
36    /// Couldn't receive the message
37    #[error("couldn't receive the message")]
38    Recv(#[source] TungsteniteError),
39    /// Couldn't decode WebSocket message, not of type text
40    #[error("couldn't decode websocket message, not of type text")]
41    WebSocketMessageType(#[source] TungsteniteError),
42    /// Disconnected from the web socket
43    #[error("the web-socket disconnected")]
44    Disconnected,
45}