Skip to main content

az_gmail_code/
error.rs

1use thiserror::Error;
2
3/// Result alias for Gmail verification-code operations.
4pub type GmailCodeResult<T> = Result<T, GmailCodeError>;
5
6/// Errors returned by Gmail API and verification-code parsing helpers.
7#[derive(Debug, Error)]
8pub enum GmailCodeError {
9    /// Client configuration failed validation before a request was sent.
10    #[error("invalid config: {0}")]
11    InvalidConfig(String),
12    /// The configured Gmail API base URL cannot be parsed.
13    #[error("invalid base url `{0}`")]
14    InvalidBaseUrl(String),
15    /// A Gmail API path could not be joined against the base URL.
16    #[error("invalid request path `{0}`")]
17    InvalidPath(String),
18    /// Network transport failed or the response body could not be read.
19    #[error("request failed: {0}")]
20    Transport(#[from] reqwest::Error),
21    /// JSON serialization or deserialization failed.
22    #[error("failed to process json payload: {0}")]
23    Json(#[from] serde_json::Error),
24    /// Gmail returned a non-success HTTP status.
25    #[error("request to `{url}` returned HTTP {status}: {body}")]
26    HttpStatus {
27        /// Final request URL.
28        url: String,
29        /// HTTP status code.
30        status: u16,
31        /// Response body decoded lossily as UTF-8.
32        body: String,
33    },
34    /// A Gmail message body part had invalid base64url content.
35    #[error("failed to decode Gmail message body for part `{part_id}`: {source}")]
36    BodyDecode {
37        /// Gmail message part id, or a synthesized id for the root body.
38        part_id: String,
39        /// Base64 decoder source error.
40        #[source]
41        source: base64::DecodeError,
42    },
43    /// A decoded body part was not valid UTF-8.
44    #[error("Gmail message body for part `{part_id}` is not valid UTF-8: {source}")]
45    BodyUtf8 {
46        /// Gmail message part id, or a synthesized id for the root body.
47        part_id: String,
48        /// UTF-8 decoder source error.
49        #[source]
50        source: std::string::FromUtf8Error,
51    },
52}