use std::time::Duration;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[cfg(feature = "http")]
#[error(transparent)]
Http(#[from] HttpError),
#[cfg(feature = "gateway")]
#[error(transparent)]
Gateway(#[from] GatewayError),
#[error(transparent)]
Model(#[from] crate::model::ModelError),
#[error("token is required")]
MissingToken,
#[cfg(feature = "client")]
#[error("event handler is required")]
MissingEventHandler,
}
#[cfg(feature = "http")]
#[derive(Debug, thiserror::Error)]
pub enum HttpError {
#[error("API error {status}: [{code}] {message}")]
Api {
status: u16,
code: String,
message: String,
},
#[error("rate limited, retry after {retry_after:?}")]
RateLimit {
retry_after: Duration,
bucket: String,
},
#[error("request failed: {0}")]
Request(#[from] reqwest::Error),
#[error("JSON serialization/deserialization failed: {0}")]
Deserialize(#[from] serde_json::Error),
#[error("token is required")]
MissingToken,
#[error("invalid authorization header: {0}")]
InvalidAuthHeader(#[from] reqwest::header::InvalidHeaderValue),
}
#[cfg(feature = "gateway")]
#[derive(Debug, thiserror::Error)]
pub enum GatewayError {
#[error("connection error: {0}")]
Connection(#[from] tokio_tungstenite::tungstenite::Error),
#[error("connection closed: {code} {reason}")]
Closed { code: u16, reason: String },
#[error("heartbeat timeout")]
HeartbeatTimeout,
#[error("invalid session (resumable: {resumable})")]
InvalidSession { resumable: bool },
#[error("authentication failed")]
AuthFailed,
#[error("deserialization failed: {0}")]
Deserialize(#[from] serde_json::Error),
}