1use prost::DecodeError;
2use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
3
4#[derive(Debug)]
6pub struct WsCloseReason {
7 pub code: CloseCode,
9
10 pub message: String,
12}
13
14#[derive(Debug)]
16pub struct WsResponseErrorDetail {
17 pub code: u64,
19 pub msg: String,
21}
22
23#[derive(Debug, thiserror::Error)]
25pub enum WsClientError {
26 #[error("unexpected response")]
28 UnexpectedResponse,
29
30 #[error("decode message error")]
32 Decode(#[from] DecodeError),
33
34 #[error("connect timeout")]
36 ConnectTimeout,
37
38 #[error("request timeout")]
40 RequestTimeout,
41
42 #[error("connection closed")]
44 ConnectionClosed {
45 reason: Option<WsCloseReason>,
47 },
48
49 #[error("Client is closed")]
51 ClientClosed,
52
53 #[error("response error: {status}: detail:{detail:?}")]
55 ResponseError {
56 status: u8,
58 detail: Option<WsResponseErrorDetail>,
60 },
61
62 #[error("cancelled")]
64 Cancelled,
65
66 #[error(transparent)]
68 InvalidUrl(#[from] url::ParseError),
69
70 #[error(transparent)]
72 Websocket(#[from] tokio_tungstenite::tungstenite::Error),
73}
74
75pub type WsClientResult<T, E = WsClientError> = std::result::Result<T, E>;