Simplify return type of most route handlers
This commit is contained in:
parent
77a87881c9
commit
5fa9190117
38 changed files with 358 additions and 414 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
||||
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
|
@ -20,7 +20,7 @@ use serde_json::{json, value::RawValue as RawJsonValue};
|
|||
pub async fn set_global_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
body: Ruma<set_global_account_data::Request<'_>>,
|
||||
) -> ConduitResult<set_global_account_data::Response> {
|
||||
) -> Result<set_global_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let data: serde_json::Value = serde_json::from_str(body.data.get())
|
||||
|
@ -41,7 +41,7 @@ pub async fn set_global_account_data_route(
|
|||
|
||||
db.flush()?;
|
||||
|
||||
Ok(set_global_account_data::Response {}.into())
|
||||
Ok(set_global_account_data::Response {})
|
||||
}
|
||||
|
||||
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||
|
@ -51,7 +51,7 @@ pub async fn set_global_account_data_route(
|
|||
pub async fn set_room_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
body: Ruma<set_room_account_data::Request<'_>>,
|
||||
) -> ConduitResult<set_room_account_data::Response> {
|
||||
) -> Result<set_room_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let data: serde_json::Value = serde_json::from_str(body.data.get())
|
||||
|
@ -72,7 +72,7 @@ pub async fn set_room_account_data_route(
|
|||
|
||||
db.flush()?;
|
||||
|
||||
Ok(set_room_account_data::Response {}.into())
|
||||
Ok(set_room_account_data::Response {})
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
||||
|
@ -82,7 +82,7 @@ pub async fn set_room_account_data_route(
|
|||
pub async fn get_global_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
body: Ruma<get_global_account_data::Request<'_>>,
|
||||
) -> ConduitResult<get_global_account_data::Response> {
|
||||
) -> Result<get_global_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let event: Box<RawJsonValue> = db
|
||||
|
@ -94,7 +94,7 @@ pub async fn get_global_account_data_route(
|
|||
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
|
||||
.content;
|
||||
|
||||
Ok(get_global_account_data::Response { account_data }.into())
|
||||
Ok(get_global_account_data::Response { account_data })
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||
|
@ -104,7 +104,7 @@ pub async fn get_global_account_data_route(
|
|||
pub async fn get_room_account_data_route(
|
||||
db: DatabaseGuard,
|
||||
body: Ruma<get_room_account_data::Request<'_>>,
|
||||
) -> ConduitResult<get_room_account_data::Response> {
|
||||
) -> Result<get_room_account_data::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let event: Box<RawJsonValue> = db
|
||||
|
@ -120,7 +120,7 @@ pub async fn get_room_account_data_route(
|
|||
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
|
||||
.content;
|
||||
|
||||
Ok(get_room_account_data::Response { account_data }.into())
|
||||
Ok(get_room_account_data::Response { account_data })
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue