error_envelope/
lib.rs

1//! A tiny, framework-agnostic error envelope for HTTP APIs.
2//!
3//! This crate provides a structured error envelope that standardizes
4//! error responses across HTTP services with fields for:
5//! - Stable machine-readable codes
6//! - Human-readable messages
7//! - Structured details
8//! - Trace IDs for debugging
9//! - Retry signals for resilience
10//!
11//! # Example
12//!
13//! ```rust
14//! use error_envelope::{Error, Code};
15//!
16//! let err = Error::not_found("User not found")
17//!     .with_details(serde_json::json!({"user_id": "123"}))
18//!     .with_trace_id("abc-def-123");
19//!
20//! assert_eq!(err.code, Code::NotFound);
21//! assert_eq!(err.status, 404);
22//! ```
23
24mod codes;
25mod error;
26mod helpers;
27mod tests;
28
29pub use codes::Code;
30pub use error::Error;
31pub use helpers::*;
32
33#[cfg(feature = "axum-support")]
34pub mod axum_support;
35
36#[cfg(feature = "anyhow-support")]
37mod anyhow_support;