Skip to main content

guerrillamail_client/
error.rs

1//! Error types for the GuerrillaMail client.
2//!
3//! This module defines all errors that can occur while interacting with the
4//! GuerrillaMail service, including network failures, parsing issues during
5//! client bootstrap, and malformed API responses.
6
7use thiserror::Error;
8
9/// Errors that can occur during GuerrillaMail operations.
10///
11/// Most errors originate either from HTTP failures (`reqwest`),
12/// malformed or unexpected responses from GuerrillaMail,
13/// or missing data required to continue an operation.
14#[derive(Error, Debug)]
15pub enum Error {
16    /// An HTTP request failed.
17    ///
18    /// This includes network connectivity issues, TLS errors,
19    /// timeouts, and non-success HTTP status codes returned
20    /// by the GuerrillaMail service.
21    #[error("HTTP request failed: {0}")]
22    Request(#[from] reqwest::Error),
23
24    /// Response was received but did not match the expected shape/content.
25    ///
26    /// Use this for “missing field”, “unexpected type”, or “schema changed” cases.
27    #[error("Unexpected GuerrillaMail response: {0}")]
28    ResponseParse(&'static str),
29
30    /// Failed to parse the API token from the GuerrillaMail homepage.
31    ///
32    /// This error typically occurs during client construction when
33    /// the expected `api_token` JavaScript variable cannot be found
34    /// or does not match the expected format.
35    #[error("Failed to parse API token from GuerrillaMail page")]
36    TokenParse,
37
38    /// Failed to parse the available domain list from the GuerrillaMail page.
39    ///
40    /// This indicates that the service response structure may have changed
41    /// or did not include the expected domain information.
42    #[error("Failed to parse domain list from GuerrillaMail page")]
43    DomainParse,
44
45    /// Failed to build or parse a regex used by the client.
46    #[error("Regex error: {0}")]
47    Regex(#[from] regex::Error),
48
49    /// Failed to construct an HTTP header value.
50    #[error("Invalid header value: {0}")]
51    HeaderValue(#[from] reqwest::header::InvalidHeaderValue),
52
53    /// Failed to deserialize JSON returned by the GuerrillaMail API.
54    ///
55    /// This usually indicates an unexpected response schema or a
56    /// partially returned / malformed payload.
57    #[error("JSON parsing error: {0}")]
58    Json(#[from] serde_json::Error),
59}