ADR-BW-011: Reuse request validation and structured HTTP errors
Validate applicable requests before handlers and expose predictable HTTP problem responses without leaking internal exception details.
| Field | Value |
|---|---|
| Status | Proposed |
| Date | 2026-11-07 |
| Owners | Architecture Enabling TeamTeamArchitecture Enabling TeamEnabling team facilitating BookWorm's architecture governance, ADRs, arc42 documentation, engineering standards, testing...Open docs |
| Affected Resources | BookWormDomainv1.0.0BookWormCore e-commerce domain for the BookWorm online bookstore, coordinating catalog discovery, customer baskets, order fulfil...Ownerarchitecture-enabling-teamDiagramRepositoryOpen docs |
| Related ADRs | ADR-BW-009: Use local CQRS handlers and the established MediatorDecision Recordv1.0.0ADR-BW-009: Use local CQRS handlers and the established MediatorReuse CQRS and Mediator.SourceGenerator for in-process request handling without treating local messages as service integ...Ownerarchitecture-enabling-teamOpen docs, ADR-BW-013: Use shared structured logging and OpenTelemetryDecision Recordv1.0.0ADR-BW-013: Use shared structured logging and OpenTelemetryProduce correlated logs, traces, metrics, and configured health signals while keeping business completion separate from ...Ownerplatform-engineering-teamOpen docs |
Context & Problem Statement
Every HTTP API in BookWormDomainv1.0.0BookWormCore e-commerce domain for the BookWorm online bookstore, coordinating catalog discovery, customer baskets, order fulfil...Ownerarchitecture-enabling-teamDiagramRepositoryOpen docs handles invalid payloads, missing resources, rate limits, and unexpected faults. If each service invents its own error schema or leaks raw stack traces, microfrontends become brittle and internal implementation details are exposed to callers.
Decision Drivers
- Early rejection: Validate inputs before executing business logic or database writes.
- Contract consistency: Return RFC-compliant
ProblemDetailsacross all HTTP services. - Information security: Keep stack traces and internal exception details out of client responses.
Options Considered
| Option | Pros | Cons |
|---|---|---|
Shared validation pipeline + standard ProblemDetails errors | Consistent client error handling; invalid requests blocked early | Services must register validators and domain exception mappings |
| Ad-hoc per-endpoint validation and errors | Zero shared-pipeline setup | Error formats and status codes diverge across services |
| Return raw exception details to clients | Faster ad-hoc debugging | Leaks internal schemas, paths, and stack traces |
Mask failures behind 200 OK responses | Uniform HTTP status | Breaks HTTP semantics and misleads retry logic |
Decision & Consequences
Chosen Option: Validate requests in a shared pre-handler pipeline and map failures to standardized ProblemDetails HTTP responses carrying a correlation trace ID. Detailed exception diagnostics remain strictly in protected OpenTelemetry logs.
- Positive: Storefront and Backoffice handle validation,
404,409,429, and500responses uniformly. - Negative: Every new command or query must include an explicit validator and exception mapping where applicable.
Compliance Criteria
- HTTP APIs must return
ProblemDetailsfor validation (400), missing (404), conflict (409), rate-limit (429), and server (500) errors. - Production error responses must never expose stack traces, SQL errors, or internal file paths.
- Request validation must run in the shared pipeline before handler execution.