Skip to main content

chio_tower/
error.rs

1//! Error types for the Chio tower middleware.
2
3use std::fmt;
4
5/// Error type for Chio tower middleware operations.
6#[derive(Debug)]
7pub enum ChioTowerError {
8    /// Failed to evaluate the request.
9    Evaluation(String),
10    /// Failed to sign a receipt.
11    ReceiptSign(String),
12    /// Failed to persist a signed receipt to the configured durable receipt
13    /// store. A durable store is attached but its append (or the conversion of
14    /// the HTTP receipt into a core receipt) failed, so the request fails closed
15    /// rather than completing without a recorded audit trail.
16    ReceiptPersist(String),
17    /// Failed to extract caller identity.
18    IdentityExtraction(String),
19    /// Inner service error.
20    Inner(Box<dyn std::error::Error + Send + Sync>),
21}
22
23impl fmt::Display for ChioTowerError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            Self::Evaluation(msg) => write!(f, "Chio evaluation error: {msg}"),
27            Self::ReceiptSign(msg) => write!(f, "Chio receipt signing error: {msg}"),
28            Self::ReceiptPersist(msg) => write!(f, "Chio receipt persistence error: {msg}"),
29            Self::IdentityExtraction(msg) => write!(f, "Chio identity extraction error: {msg}"),
30            Self::Inner(err) => write!(f, "inner service error: {err}"),
31        }
32    }
33}
34
35impl std::error::Error for ChioTowerError {
36    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37        match self {
38            Self::Inner(err) => Some(err.as_ref()),
39            _ => None,
40        }
41    }
42}