Expand description
§domainstack-envelope
Convert domainstack validation errors into structured HTTP error responses.
This crate provides the IntoEnvelopeError trait to convert ValidationError into
error_envelope::Error, producing structured JSON error responses with field-level details.
§What it provides
IntoEnvelopeErrortrait - ConvertValidationErrortoerror_envelope::Error- Field-level error mapping - Preserves error paths like
rooms[0].adults,guest.email - Structured error format - Consistent HTTP error response format with field-level details
- Metadata preservation - Includes validation metadata (min, max, etc.) in responses
§Example
use domainstack::prelude::*;
use domainstack_envelope::IntoEnvelopeError;
let mut err = domainstack::ValidationError::new();
err.push("email", "invalid_email", "Invalid email format");
err.push("age", "out_of_range", "Must be between 18 and 120");
let envelope = err.into_envelope_error();
// Produces structured error response:
// {
// "code": "VALIDATION",
// "status": 400,
// "message": "Validation failed with 2 errors",
// "details": {
// "fields": {
// "email": [{"code": "invalid_email", "message": "Invalid email format"}],
// "age": [{"code": "out_of_range", "message": "Must be between 18 and 120"}]
// }
// }
// }§Integration with Web Frameworks
Use with framework adapters for automatic error response handling:
domainstack-axum- Axum integrationdomainstack-actix- Actix-web integrationdomainstack-rocket- Rocket integration