Skip to main content

actpub_webfinger/
error.rs

1//! Error types for [`actpub-webfinger`](crate).
2
3use thiserror::Error;
4
5/// All failure modes for [`crate`].
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// The input string was not a valid `acct:` URI.
10    #[error("invalid acct URI: {0}")]
11    InvalidAcct(String),
12
13    /// A URL could not be parsed.
14    #[error("invalid URL: {0}")]
15    InvalidUrl(#[from] url::ParseError),
16
17    /// The `WebFinger` response had no subject.
18    #[error("WebFinger JRD is missing `subject`")]
19    MissingSubject,
20
21    /// The `WebFinger` subject did not match the requested resource.
22    #[error("WebFinger subject mismatch: requested {requested}, got {returned}")]
23    SubjectMismatch {
24        /// The resource URI that was requested.
25        requested: String,
26        /// The resource URI returned by the server.
27        returned: String,
28    },
29
30    /// The `WebFinger` response did not include an `ActivityPub` actor link.
31    #[error("WebFinger JRD does not reference an ActivityPub actor")]
32    MissingActorLink,
33
34    /// An HTTP transport error during client resolution.
35    #[cfg(feature = "client")]
36    #[cfg_attr(docsrs, doc(cfg(feature = "client")))]
37    #[error("HTTP error: {0}")]
38    Http(#[from] reqwest::Error),
39
40    /// The server responded with a non-success status.
41    #[cfg(feature = "client")]
42    #[cfg_attr(docsrs, doc(cfg(feature = "client")))]
43    #[error("WebFinger server returned status {0}")]
44    BadStatus(u16),
45
46    /// The server's response body exceeded the configured body cap
47    /// before it could be fully read.
48    ///
49    /// This is a `DoS` guard: a malicious or compromised `WebFinger`
50    /// responder could otherwise stream gigabytes of JSON into the
51    /// client and exhaust memory.
52    #[cfg(feature = "client")]
53    #[cfg_attr(docsrs, doc(cfg(feature = "client")))]
54    #[error("WebFinger response exceeded {0} bytes")]
55    ResponseTooLarge(u64),
56
57    /// The response body could not be parsed as JSON.
58    #[error("JSON error: {0}")]
59    Json(#[from] serde_json::Error),
60}