Validation & Errors
bloom_validate and bloom_errors provide zero-codegen declarative DTO schema validation and a standardized HTTP exception hierarchy with environment-aware error masking.
Request Schema Validation with bloom_validate
Subclass BloomRequestSchema to define request body contracts. Validation runs without code generators and accumulates all field errors in a single pass:
Inside route handlers, parse schemas using BloomRequestSchema.validateSchema():
Typed HTTP Exceptions with bloom_errors
bloom_errors provides a complete set of strongly-typed exceptions carrying status codes, machine-readable error codes, and structured detail maps:
| Exception Class | Status | Error Code | Description |
|---|---|---|---|
| BloomBadRequestException | 400 | bad_request | Malformed request or invalid parameters. |
| BloomUnauthorizedException | 401 | unauthorized | Missing or invalid session token. |
| BloomForbiddenException | 403 | forbidden | Caller lacks permissions or resource is locked. |
| BloomNotFoundException | 404 | not_found | Requested route, record, or file does not exist. |
| BloomConflictException | 409 | conflict | Resource state conflict (e.g. duplicate key). |
| BloomValidationFailedException | 422 | validation_failed | Payload validation failed (carries field error list). |
| BloomTooManyRequestsException | 429 | too_many_requests | Rate limit exceeded (supports retry-after). |
| BloomInternalException | 500 | internal_server_error | Unexpected server or infrastructure failure. |
Unified Error Middleware & Environment Masking
BloomErrorMiddleware serves as the outermost middleware on BloomApiRouter, formatting all exceptions into standardized JSON envelopes. In production (APP_ENV=production), unhandled exception traces are masked to protect server internals:
Sibling Exception Mapping
BloomErrorMapper automatically converts errors from bloom_db, bloom_auth_server, bloom_storage, and bloom_validate into their matching BloomApiException equivalents without tight compile-time coupling.