indexbus_platform_http/
errors.rs

1//! Error types and `Result` aliases for `indexbus-platform-http`.
2
3/// Result type used by this crate.
4pub type Result<T> = core::result::Result<T, Error>;
5use core::fmt;
6
7/// Errors produced by the client/server helpers in this crate.
8///
9/// ## Error semantics
10///
11/// This crate keeps errors lightweight and oriented towards human-readable reporting.
12/// In particular:
13///
14/// - Most helpers return `Error::Message` for configuration/usage issues.
15/// - Integration-specific errors are feature-gated (e.g. `reqwest`).
16/// - Errors are not currently intended for fine-grained programmatic branching.
17#[derive(Debug)]
18pub enum Error {
19    /// A simple, human-readable error message.
20    Message(String),
21
22    #[cfg(feature = "reqwest")]
23    /// An error produced by the `reqwest`-backed client implementation.
24    Reqwest(String),
25}
26
27impl Error {
28    /// Construct an [`Error::Message`].
29    pub fn msg(message: impl Into<String>) -> Self {
30        Self::Message(message.into())
31    }
32}
33
34impl fmt::Display for Error {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Error::Message(message) => write!(f, "{message}"),
38            #[cfg(feature = "reqwest")]
39            Error::Reqwest(message) => write!(f, "reqwest: {message}"),
40        }
41    }
42}
43
44#[cfg(feature = "std")]
45impl std::error::Error for Error {}