supabase_client_rs/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum Error {
8 #[error("configuration error: {0}")]
10 Config(String),
11
12 #[error("invalid URL: {0}")]
14 Url(#[from] url::ParseError),
15
16 #[error("HTTP error: {0}")]
18 Http(#[from] reqwest::Error),
19
20 #[error("JSON error: {0}")]
22 Json(#[from] serde_json::Error),
23
24 #[error("PostgREST error: {message}")]
26 PostgREST {
27 message: String,
29 code: Option<String>,
31 details: Option<String>,
33 hint: Option<String>,
35 },
36
37 #[error("authentication error: {0}")]
39 Auth(String),
40
41 #[error("storage error: {0}")]
43 Storage(String),
44
45 #[error("realtime error: {0}")]
47 Realtime(String),
48
49 #[error("function error: {0}")]
51 Function(String),
52
53 #[error("{0} is not available - enable the '{1}' feature")]
55 FeatureNotEnabled(&'static str, &'static str),
56}
57
58pub type Result<T> = std::result::Result<T, Error>;
60
61impl Error {
62 pub fn config(msg: impl Into<String>) -> Self {
64 Self::Config(msg.into())
65 }
66
67 pub fn postgrest(
69 message: impl Into<String>,
70 code: Option<String>,
71 details: Option<String>,
72 hint: Option<String>,
73 ) -> Self {
74 Self::PostgREST {
75 message: message.into(),
76 code,
77 details,
78 hint,
79 }
80 }
81}
82
83#[cfg(feature = "realtime")]
85impl From<supabase_realtime_rs::RealtimeError> for Error {
86 fn from(err: supabase_realtime_rs::RealtimeError) -> Self {
87 Self::Realtime(err.to_string())
88 }
89}