modkit_errors/lib.rs
1//! Core error types for the modkit framework
2//!
3//! This crate provides pure data types for error handling, with no dependencies
4//! on HTTP frameworks. It includes:
5//! - RFC 9457 Problem Details (`Problem`)
6//! - Error catalog support (`ErrDef`)
7#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
8
9pub mod catalog;
10pub mod problem;
11
12// Re-export commonly used types
13pub use catalog::ErrDef;
14pub use problem::{
15 APPLICATION_PROBLEM_JSON, Problem, ValidationError, ValidationErrorResponse,
16 ValidationViolation,
17};
18
19/// Helper to attach instance and `trace_id` to a Problem
20///
21/// This is a convenience function for enriching Problem instances with
22/// request-specific context before returning them as HTTP responses.
23pub fn finalize(mut p: Problem, instance: &str, trace_id: Option<String>) -> Problem {
24 p = p.with_instance(instance);
25 if let Some(tid) = trace_id {
26 p = p.with_trace_id(tid);
27 }
28 p
29}