Skip to main content

faf_radio_rust/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum RadioError {
5    #[error("WebSocket error: {0}")]
6    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
7
8    #[error("Invalid URL: {0}")]
9    InvalidUrl(#[from] url::ParseError),
10
11    #[error("JSON serialization error: {0}")]
12    Json(#[from] serde_json::Error),
13
14    #[error("Invalid frequency: {0}. Must be between 40.0 and 108.0 FM")]
15    InvalidFrequency(String),
16
17    #[error("Not connected")]
18    NotConnected,
19
20    #[error("Already connected")]
21    AlreadyConnected,
22
23    #[error("Connection closed: {0}")]
24    ConnectionClosed(String),
25
26    #[error("Server error: {0}")]
27    ServerError(String),
28
29    #[error("Timeout waiting for response")]
30    Timeout,
31
32    #[error("Max reconnect attempts reached")]
33    MaxReconnectAttemptsReached,
34}
35
36pub type Result<T> = std::result::Result<T, RadioError>;