2024-07-08 02:50:10 +00:00
|
|
|
use axum::response::{IntoResponse, Response};
|
|
|
|
use bytes::BytesMut;
|
|
|
|
use conduit::Error;
|
|
|
|
use http::StatusCode;
|
|
|
|
use http_body_util::Full;
|
|
|
|
use ruma::api::{client::uiaa::UiaaResponse, OutgoingResponse};
|
|
|
|
|
2024-07-08 18:54:42 +00:00
|
|
|
pub(crate) struct RumaResponse<T>(pub(crate) T);
|
2024-07-08 02:50:10 +00:00
|
|
|
|
|
|
|
impl From<Error> for RumaResponse<UiaaResponse> {
|
|
|
|
fn from(t: Error) -> Self { Self(t.into()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: OutgoingResponse> IntoResponse for RumaResponse<T> {
|
|
|
|
fn into_response(self) -> Response {
|
|
|
|
match self.0.try_into_http_response::<BytesMut>() {
|
|
|
|
Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(),
|
|
|
|
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|