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.
2xx and 3xx responses pass through unchanged.
Responses already in 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
Source§fn clone(&self) -> ProblemLayer
fn clone(&self) -> ProblemLayer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ProblemLayer
Source§impl Default for ProblemLayer
impl Default for ProblemLayer
Source§fn default() -> ProblemLayer
fn default() -> ProblemLayer
Returns the “default value” for a type. Read more
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