Simplify return type of most route handlers

This commit is contained in:
Jonas Platte 2022-01-22 16:58:32 +01:00
parent 77a87881c9
commit 5fa9190117
No known key found for this signature in database
GPG key ID: 7D261D771D915378
38 changed files with 358 additions and 414 deletions

View file

@ -1,4 +1,4 @@
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, Error, Result, Ruma};
use ruma::{
api::client::{
error::ErrorKind,
@ -22,7 +22,7 @@ use std::{
pub async fn send_message_event_route(
db: DatabaseGuard,
body: Ruma<send_message_event::Request<'_>>,
) -> ConduitResult<send_message_event::Response> {
) -> Result<send_message_event::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sender_device = body.sender_device.as_deref();
@ -62,7 +62,7 @@ pub async fn send_message_event_route(
.map_err(|_| Error::bad_database("Invalid txnid bytes in database."))?
.try_into()
.map_err(|_| Error::bad_database("Invalid event id in txnid data."))?;
return Ok(send_message_event::Response { event_id }.into());
return Ok(send_message_event::Response { event_id });
}
let mut unsigned = BTreeMap::new();
@ -94,7 +94,7 @@ pub async fn send_message_event_route(
db.flush()?;
Ok(send_message_event::Response::new((*event_id).to_owned()).into())
Ok(send_message_event::Response::new((*event_id).to_owned()))
}
/// # `GET /_matrix/client/r0/rooms/{roomId}/messages`
@ -107,7 +107,7 @@ pub async fn send_message_event_route(
pub async fn get_message_events_route(
db: DatabaseGuard,
body: Ruma<get_message_events::Request<'_>>,
) -> ConduitResult<get_message_events::Response> {
) -> Result<get_message_events::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
@ -235,5 +235,5 @@ pub async fn get_message_events_route(
);
}
Ok(resp.into())
Ok(resp)
}