1
Fork 0

nodeinfo: Use thiserror

This commit is contained in:
Steffo 2024-11-13 07:31:39 +01:00
parent c427af8186
commit 30610df0f5
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 16 additions and 3 deletions

View file

@ -9,6 +9,7 @@ log = "0.4.22"
reqwest = { version = "0.12.9", features = ["json", "stream"] } reqwest = { version = "0.12.9", features = ["json", "stream"] }
serde = { version = "1.0.214", features = ["derive"] } serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132" serde_json = "1.0.132"
thiserror = "2.0.3"
[dev-dependencies] [dev-dependencies]
pretty_env_logger = "0.5.0" pretty_env_logger = "0.5.0"

View file

@ -8,6 +8,7 @@
//! - <https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md> //! - <https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md>
use serde::Deserialize; use serde::Deserialize;
use thiserror::Error;
/// A variant of a NodeInfo document. /// A variant of a NodeInfo document.
/// ///
@ -309,11 +310,13 @@ impl NodeInfo {
} }
/// An error occurred during [`NodeInfo::get_latest_wellknown`]. /// An error occurred during [`NodeInfo::get_latest_wellknown`].
#[derive(Debug)] #[derive(Debug, Error)]
pub enum NodeInfoGetWellknownError { pub enum NodeInfoGetWellknownError {
/// The discovery of possible locations for NodeInfo documents failed. /// The discovery of possible locations for NodeInfo documents failed.
#[error("the discovery of possible locations for NodeInfo documents failed")]
Discovery(acrate_hostmeta::ResourceDescriptorDiscoveryError), Discovery(acrate_hostmeta::ResourceDescriptorDiscoveryError),
/// No compatible NodeInfo documents were detected at the given URL. /// No compatible NodeInfo documents were detected at the given URL.
#[error("no compatible NodeInfo documents were detected at the given URL")]
Unsupported, Unsupported,
} }
@ -446,17 +449,26 @@ impl NodeInfo2 {
} }
/// An error encountered during [`NodeInfo1::get`] or [`NodeInfo2::get`]. /// An error encountered during [`NodeInfo1::get`] or [`NodeInfo2::get`].
#[derive(Debug)] #[derive(Debug, Error)]
pub enum NodeInfoGetError { pub enum NodeInfoGetError {
/// The HTTP request failed. /// The HTTP request failed.
#[error("the HTTP request failed")]
Request(reqwest::Error), Request(reqwest::Error),
/// The `Content-Type` header of the response is missing. /// The `Content-Type` header of the response is missing.
#[error("the Content-Type header of the response is missing")]
ContentTypeMissing, ContentTypeMissing,
/// The `Content-Type` header of the response is invalid. /// The `Content-Type` header of the response is invalid.
#[error("the Content-Type header of the response is invalid")]
ContentTypeInvalid, ContentTypeInvalid,
/// The document failed to be parsed as JSON by [`reqwest`]. /// The document failed to be parsed as JSON by [`reqwest`].
#[error("the document failed to be parsed as JSON")]
Parse(reqwest::Error), Parse(reqwest::Error),
/// The returned version does not match the version of the created struct.
/// The returned NodeInfo version would not match the version of the called method.
#[error("the returned NodeInfo version would not match the version of the called method")]
Version, Version,
} }