Closed coriolinus closed 8 months ago
Hi! this is already implemented.
#[cfg(feature = "axum")]
impl axum_core::response::IntoResponse for HttpApiProblem {
fn into_response(self) -> axum_core::response::Response {
self.into()
}
}
That's good news! Does it also set the status and content type? I didn't find the implementation when browsing; only the explicit to_axum_response
method.
Hi @coriolinus, yes the implementation sets the status and content type fields because it uses the From<HttpApiProblem>
implementation that calls the to_axum_response
method.
Excellent! Thanks, and sorry for having wasted your time.
axum
handles responses based on theIntoResponse
trait. The benefit of this is composable responses; a handler can return a status code, body data, headers, or a combination of the above, and the response gets constructed appropriately.There should be an implementation like
The benefit of this implementation is that it automatically sets the status and content-type of the response, as well as json-encoding the error in the body; otherwise, it is easy for implementors to neglect to do all those things every time.