supabase_rust_gftd/
error.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum Error {
8 #[error("HTTP error: {0}")]
10 Http(#[from] reqwest::Error),
11
12 #[error("URL parse error: {0}")]
14 UrlParse(#[from] url::ParseError),
15
16 #[error("Authentication error: {0}")]
18 AuthError(#[from] supabase_rust_auth::AuthError),
19
20 #[error("PostgreSQL REST error: {0}")]
22 PostgrestError(#[from] supabase_rust_postgrest::PostgrestError),
23
24 #[error("JSON error: {0}")]
38 Json(#[from] serde_json::Error),
39
40 #[error("{0}")]
42 Other(String),
43}
44
45pub type Result<T> = std::result::Result<T, Error>;
47
48impl Error {
49 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 pub fn general(message: impl Into<String>) -> Self {
56 Self::Other(message.into())
57 }
58}
59
60pub fn api_error<E: std::fmt::Display>(error: E) -> Error {
62 Error::Other(format!("API error: {}", error))
63}