pub struct ErrorEnvelopeLayer;Expand description
Tower layer that converts error responses into a production error envelope.
Non-error responses pass through unchanged. 4xx and 5xx responses are
converted to:
{
"error": {
"statusCode": 400,
"code": "bad_request",
"message": "invalid input",
"details": null,
"timestamp": "2026-01-01T00:00:00Z",
"path": "/users",
"requestId": "..."
}
}Legacy/simple Nidus bodies shaped like
{ "error": { "code": "...", "message": "...", ... } } are parsed and
wrapped. Extra fields under error are preserved as details for non-5xx
responses. For all 5xx responses, the client-facing message is masked to
"internal server error" and details is set to null.
Error bodies larger than 64 KiB are not parsed as legacy JSON; oversized
bodies are replaced with the status-derived envelope to avoid unbounded
buffering.
When crate::context::RequestContext is present, its request ID is copied
into error.requestId; otherwise that field is an empty string. Install the
validated request ID and request context layers, or use
crate::middleware::ApiDefaults::production, when clients need stable
request IDs in error responses.
Implementations§
Trait Implementations§
Source§impl Clone for ErrorEnvelopeLayer
impl Clone for ErrorEnvelopeLayer
Source§fn clone(&self) -> ErrorEnvelopeLayer
fn clone(&self) -> ErrorEnvelopeLayer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more