use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("configuration error: {0}")]
Config(String),
#[error("invalid URL: {0}")]
Url(#[from] url::ParseError),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("PostgREST error: {message}")]
PostgREST {
message: String,
code: Option<String>,
details: Option<String>,
hint: Option<String>,
},
#[error("authentication error: {0}")]
Auth(String),
#[error("storage error: {0}")]
Storage(String),
#[error("realtime error: {0}")]
Realtime(String),
#[error("function error: {0}")]
Function(String),
#[error("{0} is not available - enable the '{1}' feature")]
FeatureNotEnabled(&'static str, &'static str),
}
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
pub fn config(msg: impl Into<String>) -> Self {
Self::Config(msg.into())
}
pub fn postgrest(
message: impl Into<String>,
code: Option<String>,
details: Option<String>,
hint: Option<String>,
) -> Self {
Self::PostgREST {
message: message.into(),
code,
details,
hint,
}
}
}
#[cfg(feature = "realtime")]
impl From<supabase_realtime_rs::RealtimeError> for Error {
fn from(err: supabase_realtime_rs::RealtimeError) -> Self {
Self::Realtime(err.to_string())
}
}