Skip to main content

Module canonical_error_layer

Module canonical_error_layer 

Source
Expand description

Canonical error middleware (DESIGN.md §3.2 / §3.6 / §3.7).

Post-processes responses with Content-Type: application/problem+json, filling missing trace_id (W3C traceparentx-trace-idx-request-id → span-id fallback) and instance (request URI path). Logs at warn! for 4xx / error! for 5xx with structured fields.

Catch-all behaviour (panics, unknown error types) is out of scope per PRD §4.2 — CatchPanicLayer handles panics; handlers are responsible for typing their errors as CanonicalError.

Functions§

canonical_error_middleware
Tower middleware function that fills trace_id / instance on canonical Problem responses and logs at warn! (4xx) / error! (5xx).