1 stable release
| 1.0.0 | Jan 6, 2026 |
|---|
#2016 in HTTP server
Used in 4 crates
245KB
4K
SLoC
domainstack-envelope
Convert domainstack validation errors to error-envelope HTTP error format. Part of the domainstack full-stack validation ecosystem.
Usage
Add this to your Cargo.toml:
[dependencies]
domainstack = "1.0"
domainstack-envelope = "1.0"
Convert validation errors to error-envelope format:
use domainstack::{Validate, ValidationError};
use domainstack_envelope::IntoEnvelopeError;
use error_envelope::Error;
fn create_user(user: User) -> Result<User, Error> {
user.validate()
.map_err(|e| e.into_envelope_error())?;
Ok(user)
}
Error Format
Converts structured validation errors to error-envelope's standard HTTP error format:
{
"error": {
"code": "validation_failed",
"message": "Validation failed",
"details": {
"email": ["Invalid email format"],
"age": ["Must be at least 18"]
}
}
}
Features
- Structured field paths - Nested fields like
user.address.citymap correctly - Multiple violations per field - All errors preserved
- HTTP status codes - Returns 400 Bad Request for validation errors
- Standard format - Compatible with error-envelope ecosystem
Framework Integration
Use with framework adapters for automatic error conversion:
// Axum
use domainstack_axum::{DomainJson, ErrorResponse};
async fn handler(DomainJson(user): DomainJson<User>) -> Result<Json<User>, ErrorResponse> {
// Validation errors automatically converted to error-envelope format
Ok(Json(user))
}
// Actix-web
use domainstack_actix::{DomainJson, ErrorResponse};
async fn handler(user: DomainJson<User>) -> Result<HttpResponse, ErrorResponse> {
// Validation errors automatically converted to error-envelope format
Ok(HttpResponse::Ok().json(user.into_inner()))
}
Documentation
For complete documentation, examples, and usage guides, see:
License
Apache 2.0
Dependencies
~1.1–2.2MB
~43K SLoC