cripsy_binary_api/transport/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum TransportError {
7 #[error("error de red: {0}")]
8 Io(String),
9
10 #[error("url inválida: {0}")]
11 Url(String),
12
13 #[error("timeout en fase '{phase}' tras {ms} ms")]
14 Timeout { phase: String, ms: u64 },
15
16 #[error("error TLS: {0}")]
17 Tls(String),
18
19 #[error("websocket cerrado por el par")]
20 Closed,
21
22 #[error("HTTP {status}: {body}")]
23 Http { status: u16, body: String },
24
25 #[error("no se pudo codificar/decodificar el mensaje: {0}")]
26 Codec(String),
27}
28
29#[cfg(any(feature = "async", feature = "blocking"))]
30impl From<reqwest::Error> for TransportError {
31 fn from(e: reqwest::Error) -> Self {
32 if e.is_timeout() {
33 TransportError::Timeout {
34 phase: "http".into(),
35 ms: 0,
36 }
37 } else {
38 TransportError::Io(e.to_string())
39 }
40 }
41}