use axum::{ extract::rejection::{JsonRejection, PathRejection}, response::{IntoResponse, Response}, routing::post, Json, Router, }; use axum_macros::FromRequest; use serde::Deserialize; fn main() { let _: Router = Router::new().route("/{something}", post(handler)); } async fn handler(_: Args) {} #[derive(Deserialize)] struct Payload { value: String, } #[derive(FromRequest)] #[from_request(rejection(MyError))] struct Args { #[from_request(via(axum::extract::Path))] something: String, #[from_request(via(Json))] request: Option, } struct MyError(Response); impl From for MyError { fn from(rejection: PathRejection) -> Self { Self(rejection.into_response()) } } impl From for MyError { fn from(rejection: JsonRejection) -> Self { Self(rejection.into_response()) } } impl IntoResponse for MyError { fn into_response(self) -> Response { self.0 } }