pub struct ProblemLayer;Expand description
Tower middleware layer that converts non-problem error responses to RFC 9457.
Any 4xx or 5xx response that doesn’t have Content-Type: application/problem+json
is replaced with a Problem response using the same HTTP status code.
The original response body (up to 4 KB) is preserved as the problem detail
field — so axum extractor error messages like “missing field email” are not
silently discarded. 2xx and 3xx responses pass through unchanged. Responses
already in application/problem+json format also pass through unchanged.
Apply it last (outermost layer) in your axum router so it catches errors from all other middleware and extractors:
use axum::Router;
use axum_problem::ProblemLayer;
let app: Router = Router::new()
/* ... routes and other layers ... */
.layer(ProblemLayer);Trait Implementations§
Source§impl Clone for ProblemLayer
impl Clone for ProblemLayer
impl Copy for ProblemLayer
Source§impl Default for ProblemLayer
impl Default for ProblemLayer
Auto Trait Implementations§
impl Freeze for ProblemLayer
impl RefUnwindSafe for ProblemLayer
impl Send for ProblemLayer
impl Sync for ProblemLayer
impl Unpin for ProblemLayer
impl UnsafeUnpin for ProblemLayer
impl UnwindSafe for ProblemLayer
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