tuwunel_api/router/
response.rs1use axum::response::{IntoResponse, Response};
2use bytes::BytesMut;
3use http::StatusCode;
4use http_body_util::Full;
5use ruma::api::{OutgoingResponse, client::uiaa::UiaaResponse};
6use tuwunel_core::{Error, error};
7
8pub struct RumaResponse<T>(
12 pub T,
14)
15where
16 T: OutgoingResponse;
17
18impl From<Error> for RumaResponse<UiaaResponse> {
19 fn from(t: Error) -> Self { Self(t.into()) }
20}
21
22impl<T> IntoResponse for RumaResponse<T>
23where
24 T: OutgoingResponse,
25{
26 fn into_response(self) -> Response {
27 self.0
28 .try_into_http_response::<BytesMut>()
29 .inspect_err(|e| error!("response error: {e}"))
30 .map_or_else(
31 |_| StatusCode::INTERNAL_SERVER_ERROR.into_response(),
32 |r| {
33 r.map(BytesMut::freeze)
34 .map(Full::new)
35 .into_response()
36 },
37 )
38 }
39}