pub struct ErrorInterceptorLayer { /* private fields */ }Expand description
Middleware layer that enables error enrichment with request context.
This layer captures request information (method, URI, headers) and makes it available to the error enricher callback.
§Example
use axum::Router;
use axum_anyhow::ErrorInterceptorLayer;
use serde_json::json;
// Create the layer with an enricher
let enricher_layer = ErrorInterceptorLayer::new(|builder, ctx| {
builder.meta(json!({
"method": ctx.method().as_str(),
"uri": ctx.uri().to_string(),
"user_agent": ctx.headers()
.get("user-agent")
.and_then(|v| v.to_str().ok())
.unwrap_or("unknown"),
}))
});
// Apply the middleware
let app: Router = Router::new()
.layer(enricher_layer);Implementations§
Source§impl ErrorInterceptorLayer
impl ErrorInterceptorLayer
Trait Implementations§
Source§impl Clone for ErrorInterceptorLayer
impl Clone for ErrorInterceptorLayer
Source§fn clone(&self) -> ErrorInterceptorLayer
fn clone(&self) -> ErrorInterceptorLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ErrorInterceptorLayer
impl !RefUnwindSafe for ErrorInterceptorLayer
impl Send for ErrorInterceptorLayer
impl Sync for ErrorInterceptorLayer
impl Unpin for ErrorInterceptorLayer
impl UnsafeUnpin for ErrorInterceptorLayer
impl !UnwindSafe for ErrorInterceptorLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more