Skip to main content

rp_supabase_functions/
error.rs

1use reqwest::StatusCode;
2
3/// Errors returned by [`crate::FunctionsClient`] and [`crate::InvokeBuilder`].
4#[derive(Debug, thiserror::Error)]
5pub enum FunctionsError {
6    /// The function name is empty, `.` or `..`, or contains `/`, tab, CR, or LF.
7    #[error(
8        "invalid function name {0:?}: it must be non-empty, must not be '.' or '..', and must not contain '/', tab, CR, or LF"
9    )]
10    InvalidFunctionName(String),
11    /// The project URL cannot hold the functions path.
12    #[error("invalid project URL: {0}")]
13    Url(#[from] url::ParseError),
14    /// The project URL cannot be a base URL (for example `mailto:`).
15    #[error("project URL cannot be a base URL")]
16    UrlNotBase,
17    /// A header name is not valid.
18    #[error("invalid header name: {0}")]
19    HeaderName(#[from] reqwest::header::InvalidHeaderName),
20    /// A header value is not valid.
21    #[error("invalid header value: {0}")]
22    HeaderValue(#[from] reqwest::header::InvalidHeaderValue),
23    /// The request body cannot be serialized to JSON.
24    #[error("failed to serialize request body: {0}")]
25    Serialize(#[source] serde_json::Error),
26    /// The request did not complete (connection, TLS, timeout, or body read failure).
27    #[error("transport error: {0}")]
28    Transport(#[from] reqwest::Error),
29    /// The Supabase relay failed to reach the function (`x-relay-error: true`).
30    #[error("relay error {status}: {body}")]
31    Relay {
32        /// HTTP status returned by the relay.
33        status: StatusCode,
34        /// Response body text.
35        body: String,
36    },
37    /// The function returned a non-2xx status.
38    #[error("function returned {status}: {body}")]
39    Http {
40        /// HTTP status returned by the function.
41        status: StatusCode,
42        /// Response body text.
43        body: String,
44    },
45    /// The response body is not valid JSON for the requested type.
46    #[error("failed to decode response body: {0}")]
47    Decode(#[source] serde_json::Error),
48}