supabase_rust_realtime/
error.rs

1use thiserror::Error;
2
3/// エラー型
4#[derive(Error, Debug)]
5pub enum RealtimeError {
6    #[error("WebSocket error: {0}")]
7    WebSocketError(#[from] tokio_tungstenite::tungstenite::Error),
8
9    #[error("URL parse error: {0}")]
10    UrlParseError(#[from] url::ParseError),
11
12    #[error("JSON serialization error: {0}")]
13    SerializationError(#[from] serde_json::Error),
14
15    #[error("Subscription error: {0}")]
16    SubscriptionError(String),
17
18    #[error("Channel error: {0}")]
19    ChannelError(String),
20
21    #[error("Connection error: {0}")]
22    ConnectionError(String),
23}
24
25impl RealtimeError {
26    // Consider if this helper is still needed or if direct construction is clearer
27    #[allow(dead_code)] // Keep if potentially useful, otherwise remove
28    pub fn new(message: String) -> Self {
29        Self::ChannelError(message)
30    }
31}
32
33// Note: The From<SendError> impl is kept separate (likely in client.rs or lib.rs)
34// because it depends on `tokio_tungstenite::tungstenite::Message` which might
35// not be needed directly in this error module.
36
37// Add conversion from SendError if needed, otherwise keep it in lib.rs/client.rs where Message is defined
38// impl From<tokio::sync::mpsc::error::SendError<Message>> for RealtimeError {
39//     fn from(err: tokio::sync::mpsc::error::SendError<Message>) -> Self {
40//         RealtimeError::ConnectionError(format!("Failed to send message to socket task: {}", err))
41//     }
42// }