1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum Error {
8 #[error("HTTP {status}: {body}")]
10 Http {
11 status: u16,
13 body: String,
15 },
16
17 #[error("Redirect to: {url}")]
20 Redirect {
21 url: String,
23 },
24
25 #[error("record not found")]
27 NotFound,
28
29 #[error("JSON error: {0}")]
31 Json(#[from] serde_json::Error),
32
33 #[error("URL error: {0}")]
35 Url(#[from] url::ParseError),
36
37 #[error("signature error: {0}")]
39 Signature(String),
40
41 #[error("transport error: {0}")]
43 Transport(String),
44
45 #[error("protocol error: {0}")]
47 Protocol(String),
48}
49
50#[cfg(feature = "client")]
51impl From<reqwest::Error> for Error {
52 fn from(e: reqwest::Error) -> Self {
53 if let Some(status) = e.status() {
54 Error::Http {
55 status: status.as_u16(),
56 body: e.to_string(),
57 }
58 } else {
59 Error::Transport(e.to_string())
60 }
61 }
62}
63
64#[cfg(feature = "websocket")]
65impl From<tokio_tungstenite::tungstenite::Error> for Error {
66 fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
67 Error::Transport(e.to_string())
68 }
69}