move RumaResponse out of core Error; cleanup Error conversions.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
59d86d3641
commit
7ba0777bd3
9 changed files with 122 additions and 110 deletions
|
@ -44,6 +44,7 @@ conduit-service.workspace = true
|
|||
futures-util.workspace = true
|
||||
hmac.workspace = true
|
||||
http.workspace = true
|
||||
http-body-util.workspace = true
|
||||
hyper.workspace = true
|
||||
image.workspace = true
|
||||
ipaddress.workspace = true
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use axum_client_ip::InsecureClientIp;
|
||||
use conduit::{warn, RumaResponse};
|
||||
use conduit::warn;
|
||||
use ruma::{
|
||||
api::client::{error::ErrorKind, membership::mutual_rooms, room::get_summary},
|
||||
events::room::member::MembershipState,
|
||||
OwnedRoomId,
|
||||
};
|
||||
|
||||
use crate::{services, Error, Result, Ruma};
|
||||
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||
|
||||
/// # `GET /_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms`
|
||||
///
|
||||
|
|
|
@ -9,7 +9,8 @@ extern crate conduit_service as service;
|
|||
pub(crate) use conduit::{debug_info, debug_warn, utils, Error, Result};
|
||||
pub(crate) use service::{pdu::PduEvent, services, user_is_local};
|
||||
|
||||
pub(crate) use crate::router::{Ruma, RumaResponse};
|
||||
pub(crate) use self::router::Ruma;
|
||||
pub use self::router::RumaResponse;
|
||||
|
||||
conduit::mod_ctor! {}
|
||||
conduit::mod_dtor! {}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
mod auth;
|
||||
mod handler;
|
||||
mod request;
|
||||
mod response;
|
||||
|
||||
use std::{mem, ops::Deref};
|
||||
|
||||
use axum::{async_trait, body::Body, extract::FromRequest};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
pub(super) use conduit::error::RumaResponse;
|
||||
use conduit::{debug, debug_warn, trace, warn};
|
||||
use ruma::{
|
||||
api::{client::error::ErrorKind, IncomingRequest},
|
||||
|
@ -14,6 +14,7 @@ use ruma::{
|
|||
};
|
||||
|
||||
pub(super) use self::handler::RouterExt;
|
||||
pub use self::response::RumaResponse;
|
||||
use self::{auth::Auth, request::Request};
|
||||
use crate::{service::appservice::RegistrationInfo, services, Error, Result};
|
||||
|
||||
|
|
22
src/api/router/response.rs
Normal file
22
src/api/router/response.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
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};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RumaResponse<T>(pub T);
|
||||
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue