diff --git a/examples/customize-extractor-error/src/derive_from_request.rs b/examples/customize-extractor-error/src/derive_from_request.rs index 7295823e..84fd9bbf 100644 --- a/examples/customize-extractor-error/src/derive_from_request.rs +++ b/examples/customize-extractor-error/src/derive_from_request.rs @@ -15,10 +15,11 @@ use axum::{ extract::rejection::JsonRejection, extract::FromRequest, http::StatusCode, response::IntoResponse, }; +use serde::Serialize; use serde_json::{json, Value}; pub async fn handler(Json(value): Json) -> impl IntoResponse { - Json(dbg!(value)); + Json(dbg!(value)) } // create an extractor that internally uses `axum::Json` but has a custom rejection @@ -26,6 +27,14 @@ pub async fn handler(Json(value): Json) -> impl IntoResponse { #[from_request(via(axum::Json), rejection(ApiError))] pub struct Json(T); +// We implement `IntoResponse` for our extractor so it can be used as a response +impl IntoResponse for Json { + fn into_response(self) -> axum::response::Response { + let Self(value) = self; + axum::Json(value).into_response() + } +} + // We create our own rejection type #[derive(Debug)] pub struct ApiError {