domainstack-envelope

Crates.iodomainstack-envelope
lib.rsdomainstack-envelope
version1.0.0
created_at2026-01-06 13:50:54.681053+00
updated_at2026-01-06 13:50:54.681053+00
descriptionError envelope integration for domainstack: convert validation errors to structured HTTP error responses
homepage
repositoryhttps://github.com/blackwell-systems/domainstack
max_upload_size
id2025896
size22,709
Blackwell Systems (blackwell-systems)

documentation

https://docs.rs/domainstack-envelope

README

domainstack-envelope

Blackwell Systems™ Crates.io Documentation License: MIT OR Apache-2.0

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.city map 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

Commit count: 327

cargo fmt