livespeech_sdk/
error.rs

1//! Error types for the LiveSpeech SDK
2
3use crate::types::ErrorCode;
4use thiserror::Error;
5
6/// Main error type for the LiveSpeech SDK
7#[derive(Debug, Error)]
8pub enum LiveSpeechError {
9    /// Configuration error
10    #[error("Configuration error: {0}")]
11    Config(#[from] crate::types::ConfigError),
12
13    /// Connection error
14    #[error("Connection error: {0}")]
15    Connection(String),
16
17    /// WebSocket error
18    #[error("WebSocket error: {0}")]
19    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
20
21    /// JSON serialization/deserialization error
22    #[error("JSON error: {0}")]
23    Json(#[from] serde_json::Error),
24
25    /// URL parsing error
26    #[error("URL error: {0}")]
27    Url(#[from] url::ParseError),
28
29    /// Not connected error
30    #[error("Not connected")]
31    NotConnected,
32
33    /// Session not started error
34    #[error("No active session")]
35    NoActiveSession,
36
37    /// Session already active error
38    #[error("Session already active")]
39    SessionAlreadyActive,
40
41    /// Already streaming audio
42    #[error("Already streaming")]
43    AlreadyStreaming,
44
45    /// Not streaming audio
46    #[error("Not streaming")]
47    NotStreaming,
48
49    /// Session error from server
50    #[error("Session error: {0}")]
51    SessionError(String),
52
53    /// Invalid parameter
54    #[error("Invalid parameter: {0}")]
55    InvalidParameter(String),
56
57    /// Connection timeout
58    #[error("Connection timeout")]
59    ConnectionTimeout,
60
61    /// Authentication failed
62    #[error("Authentication failed: {0}")]
63    AuthenticationFailed(String),
64
65    /// Server error
66    #[error("Server error ({code}): {message}")]
67    ServerError { code: ErrorCode, message: String },
68
69    /// Channel send error
70    #[error("Channel send error")]
71    ChannelSend,
72
73    /// Channel receive error
74    #[error("Channel receive error")]
75    ChannelReceive,
76
77    /// Reconnection failed
78    #[error("Reconnection failed after {attempts} attempts")]
79    ReconnectionFailed { attempts: u32 },
80}
81
82/// Result type alias for LiveSpeech operations
83pub type Result<T> = std::result::Result<T, LiveSpeechError>;