Skip to main content

fluxer/
error.rs

1//! Error types used across the library.
2
3use thiserror::Error;
4
5/// The error type returned by pretty much everything in the library.
6///
7/// You can match on the variant to figure out what went wrong. Most of the time
8/// you'll see [`Api`](ClientError::Api) for things like missing permissions, or
9/// [`ConnectionClosed`](ClientError::ConnectionClosed) when the gateway drops
10/// (which the client handles automatically by reconnecting).
11#[derive(Error, Debug)]
12pub enum ClientError {
13    #[error("WebSocket error: {0}")]
14    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
15
16    /// Not for bad status codes like 403 or 404 -- those show up as
17    /// [`Api`](ClientError::Api). This is for transport-level stuff like
18    /// DNS failures, TLS errors, timeouts, etc.
19    #[error("HTTP error: {0}")]
20    Http(#[from] reqwest::Error),
21
22    #[error("JSON error: {0}")]
23    Json(#[from] serde_json::Error),
24
25    #[error("Connection closed by server")]
26    ConnectionClosed,
27
28    /// The string contains the status and body, like
29    /// `"HTTP 403: {\"message\": \"Missing Permissions\"}"`.
30    #[error("API error: {0}")]
31    Api(String),
32
33    /// Timeout waiting for `VOICE_SERVER_UPDATE`, LiveKit connection failure, etc.
34    #[error("Voice error: {0}")]
35    Voice(String),
36}