1use crate::types::Response;
4use crate::types::WSResult;
5use thiserror::Error;
6use tokio_tungstenite::tungstenite;
7
8pub type HassResult<T> = std::result::Result<T, HassError>;
9
10#[derive(Error, Debug)]
12pub enum HassError {
13 #[error("Authentication failed: {0}")]
15 AuthenticationFailed(String),
16
17 #[error("Unable to deserialize received value: {0}")]
19 UnableToDeserialize(#[from] serde_json::error::Error),
20
21 #[error("Connection closed unexpectedly")]
23 ConnectionClosed,
24
25 #[error("Unable to send the message on channel: {0}")]
27 SendError(String),
28
29 #[error("Unable to receive a message on channel: {0}")]
30 RecvError(String),
31
32 #[error("Tungstenite error: {0}")]
34 TungsteniteError(#[from] tungstenite::error::Error),
35
36 #[error("The received payload is unknown {0:?}")]
38 UnknownPayloadReceived(Response),
39
40 #[error("Received an unexpected message: {0:?}")]
42 UnexpectedMessage(tungstenite::Message),
43
44 #[error("ResponseError: {0:?}")]
46 ResponseError(WSResult),
47
48 #[error("Generic Error: {0}")]
50 Generic(String),
51}