diff --git a/api-error/src/lib.rs b/api-error/src/lib.rs index ec51766..2f23b75 100644 --- a/api-error/src/lib.rs +++ b/api-error/src/lib.rs @@ -449,6 +449,7 @@ pub mod axum { body::Body, response::{IntoResponse, Response}, }; + use http::{HeaderValue, header::CONTENT_TYPE}; use serde_core::{Serialize, ser::SerializeMap}; #[doc(hidden)] @@ -536,10 +537,13 @@ pub mod axum { impl IntoResponse for ApiErrorResponse<'_> { fn into_response(self) -> Response { + const APPLICATION_JSON: HeaderValue = HeaderValue::from_static("application/json"); let body = serde_json::to_vec(&self).expect("AxumApiError serialization should not fail"); - (self.0.status_code(), Body::from(body)).into_response() + let mut res = (self.0.status_code(), Body::from(body)).into_response(); + res.headers_mut().insert(CONTENT_TYPE, APPLICATION_JSON); + res } } }