supabase_rust_gftd/
error.rs

1//! Error types for Supabase Rust client
2
3use thiserror::Error;
4
5/// Error types for the Supabase client
6#[derive(Error, Debug)]
7pub enum Error {
8    /// HTTP error from reqwest
9    #[error("HTTP error: {0}")]
10    Http(#[from] reqwest::Error),
11    
12    /// URL parse error
13    #[error("URL parse error: {0}")]
14    UrlParse(#[from] url::ParseError),
15    
16    /// Authentication error
17    #[error("Authentication error: {0}")]
18    AuthError(#[from] supabase_rust_auth::AuthError),
19    
20    /// PostgreSQL REST API error
21    #[error("PostgreSQL REST error: {0}")]
22    PostgrestError(#[from] supabase_rust_postgrest::PostgrestError),
23    
24    /// Storage error
25    // #[error("Storage error: {0}")]
26    // StorageError(#[from] supabase_rust_storage::StorageError),
27    
28    /// Realtime subscription error
29    // #[error("Realtime error: {0}")]
30    // RealtimeError(#[from] supabase_rust_realtime::RealtimeError),
31    
32    /// Edge Functions error
33    // #[error("Functions error: {0}")]
34    // FunctionsError(#[from] supabase_rust_functions::FunctionsError),
35    
36    /// JSON serialization/deserialization error
37    #[error("JSON error: {0}")]
38    Json(#[from] serde_json::Error),
39    
40    /// Generic error
41    #[error("{0}")]
42    Other(String),
43}
44
45/// Result type for the Supabase client
46pub type Result<T> = std::result::Result<T, Error>;
47
48impl Error {
49    /// Create a new API error
50    pub fn api_error(code: impl Into<String> + std::fmt::Display, message: impl Into<String> + std::fmt::Display) -> Self {
51        Self::Other(format!("API error: {message} (code: {code})"))
52    }
53    
54    /// Create a new general error
55    pub fn general(message: impl Into<String>) -> Self {
56        Self::Other(message.into())
57    }
58}
59
60/// Prints an API error from the Supabase API
61pub fn api_error<E: std::fmt::Display>(error: E) -> Error {
62    Error::Other(format!("API error: {}", error))
63}