openidauthzen 0.1.0-alpha.1

OpenID AuthZEN Authorization API 1.0 — Policy Decision and Enforcement Points for Rust
Documentation
//! Error types for the openidauthzen library.
//!
//! [`enum@Error`] is the single error type for all fallible operations —
//! HTTP transport, discovery validation, JSON serialization, and
//! client construction.

use thiserror::Error;

/// Unified error type for the openidauthzen library.
///
/// Covers HTTP transport failures, AuthZEN protocol violations, and
/// serialization errors.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
    /// An HTTP request failed at the transport level (DNS, TLS, timeout, etc.).
    #[error("HTTP request failed: {0}")]
    Http(#[source] Box<dyn std::error::Error + Send + Sync>),

    /// The PDP returned a non-success HTTP status code.
    #[error("HTTP {status}: {body}")]
    HttpStatus {
        /// HTTP status code (e.g. `400`, `401`, `403`, `500`).
        status: u16,
        /// Response body, typically an error message string.
        body: String,
    },

    /// Failed to construct the underlying HTTP client.
    ///
    /// Only available when the `reqwest` feature is enabled.
    #[error("failed to build HTTP client: {0}")]
    #[cfg(feature = "reqwest")]
    HttpClient(#[source] reqwest::Error),

    /// The PDP URL could not be parsed or is not a valid HTTPS URL.
    #[error("invalid PDP URL: {0}")]
    InvalidPdpUrl(String),

    /// The `policy_decision_point` field in the discovery response does
    /// not match the identifier used to construct the well-known URL.
    #[error("PDP identifier mismatch: expected `{expected}`, got `{got}`")]
    PdpMismatch {
        /// The PDP identifier used for discovery.
        expected: String,
        /// The `policy_decision_point` value returned in the metadata.
        got: String,
    },

    /// [`crate::client::AuthZenClient::discover`] has not been called
    /// for this PDP, so endpoint URLs cannot be resolved.
    #[error("PDP not cached: {0}")]
    NotCached(String),

    /// The PDP returned a response body that could not be deserialized
    /// into the expected type.
    #[error("invalid response: {0}")]
    InvalidResponse(#[source] serde_json::Error),

    /// Failed to serialize a request body to JSON.
    #[error("serialization error: {0}")]
    Serialization(#[source] serde_json::Error),
}