1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
pub use actix_http::client::{
ConnectError, FreezeRequestError, InvalidUrl, SendRequestError,
};
pub use actix_http::error::PayloadError;
pub use actix_http::http::Error as HttpError;
pub use actix_http::ws::HandshakeError as WsHandshakeError;
pub use actix_http::ws::ProtocolError as WsProtocolError;
use actix_http::ResponseError;
use serde_json::error::Error as JsonError;
use actix_http::http::{header::HeaderValue, StatusCode};
use derive_more::{Display, From};
#[derive(Debug, Display, From)]
pub enum WsClientError {
#[display(fmt = "Invalid response status")]
InvalidResponseStatus(StatusCode),
#[display(fmt = "Invalid upgrade header")]
InvalidUpgradeHeader,
#[display(fmt = "Invalid connection header")]
InvalidConnectionHeader(HeaderValue),
#[display(fmt = "Missing CONNECTION header")]
MissingConnectionHeader,
#[display(fmt = "Missing SEC-WEBSOCKET-ACCEPT header")]
MissingWebSocketAcceptHeader,
#[display(fmt = "Invalid challenge response")]
InvalidChallengeResponse(String, HeaderValue),
#[display(fmt = "{}", _0)]
Protocol(WsProtocolError),
#[display(fmt = "{}", _0)]
SendRequest(SendRequestError),
}
impl std::error::Error for WsClientError {}
impl From<InvalidUrl> for WsClientError {
fn from(err: InvalidUrl) -> Self {
WsClientError::SendRequest(err.into())
}
}
impl From<HttpError> for WsClientError {
fn from(err: HttpError) -> Self {
WsClientError::SendRequest(err.into())
}
}
#[derive(Debug, Display, From)]
pub enum JsonPayloadError {
#[display(fmt = "Content type error")]
ContentType,
#[display(fmt = "Json deserialize error: {}", _0)]
Deserialize(JsonError),
#[display(fmt = "Error that occur during reading payload: {}", _0)]
Payload(PayloadError),
}
impl std::error::Error for JsonPayloadError {}
impl ResponseError for JsonPayloadError {}