{"id":1204,"hash":"77fdd62f4dacf6572bb260ee363db1beb4cf3d7ecc4d2e0f540aa580a2c4f0d3","pattern":"Customizing errors from Query extractor in Rust with Axum","full_message":"I have followed the example provided here to customize the extractor error for the Json extractor:\n\n#[derive(FromRequest)]\n#[from_request(via(axum::Json), rejection(ApiError))]\npub struct JsonExtractor<T>(pub T);\n\n#[axum::debug_handler]\npub(crate) async fn create(\n    state: State<AppState>,\n    JsonExtractor(json): JsonExtractor<RouteBody>,\n) -> Result<axum::Json<Customer>, ApiError>\n\nThis works great, but when I try the same for extracting from the Query, I get errors:\n\n#[derive(FromRequest)]\n#[from_request(via(axum::extract::Query), rejection(ApiError))]\npub struct QueryExtractor<T>(pub T);\n\n#[axum::debug_handler]\npub(crate) async fn list(\n    state: State<AppState>,\n    query: QueryExtractor<RouteQuery>, // errors here\n) -> Result<axum::Json<List<Customer>>, ApiError>\n\nthe trait bound `QueryExtractor<customers::list::RouteQuery>: FromRequest<AppState, hyper::Body, _>` is not satisfied\nFunction argument is not a valid axum extractor.","ecosystem":"cargo","package_name":"rust-axum","package_version":null,"solution":"The difference is Json implements FromRequest while Query implements FromRequestParts (the latter doesn't consume the request body).\n\nSo you'd use #[derive(FromRequestParts) instead:\n\nThis works similarly to #[derive(FromRequest)] except it uses FromRequestParts. All the same options are supported.","confidence":0.75,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/76302607/customizing-errors-from-query-extractor-in-rust-with-axum","votes":2,"created_at":"2026-04-19T04:52:35.595531+00:00","updated_at":"2026-04-19T04:52:35.595531+00:00"}