log error for /publicRooms requests, simplify it a bit

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-12 19:20:15 -04:00 committed by June
parent 9b5c8c124e
commit e5307d44ca
3 changed files with 25 additions and 22 deletions

View file

@ -34,15 +34,7 @@ use crate::{services, Error, Result, Ruma};
pub async fn get_public_rooms_filtered_route( pub async fn get_public_rooms_filtered_route(
body: Ruma<get_public_rooms_filtered::v3::Request>, body: Ruma<get_public_rooms_filtered::v3::Request>,
) -> Result<get_public_rooms_filtered::v3::Response> { ) -> Result<get_public_rooms_filtered::v3::Response> {
if !services() let response = get_public_rooms_filtered_helper(
.globals
.config
.allow_public_room_directory_without_auth
{
let _sender_user = body.sender_user.as_ref().expect("user is authenticated");
}
get_public_rooms_filtered_helper(
body.server.as_deref(), body.server.as_deref(),
body.limit, body.limit,
body.since.as_deref(), body.since.as_deref(),
@ -50,6 +42,12 @@ pub async fn get_public_rooms_filtered_route(
&body.room_network, &body.room_network,
) )
.await .await
.map_err(|e| {
warn!("Failed to return our /publicRooms: {e}");
Error::BadRequest(ErrorKind::Unknown, "Failed to return this server's public room list.")
})?;
Ok(response)
} }
/// # `GET /_matrix/client/v3/publicRooms` /// # `GET /_matrix/client/v3/publicRooms`
@ -60,14 +58,6 @@ pub async fn get_public_rooms_filtered_route(
pub async fn get_public_rooms_route( pub async fn get_public_rooms_route(
body: Ruma<get_public_rooms::v3::Request>, body: Ruma<get_public_rooms::v3::Request>,
) -> Result<get_public_rooms::v3::Response> { ) -> Result<get_public_rooms::v3::Response> {
if !services()
.globals
.config
.allow_public_room_directory_without_auth
{
let _sender_user = body.sender_user.as_ref().expect("user is authenticated");
}
let response = get_public_rooms_filtered_helper( let response = get_public_rooms_filtered_helper(
body.server.as_deref(), body.server.as_deref(),
body.limit, body.limit,
@ -75,7 +65,11 @@ pub async fn get_public_rooms_route(
&Filter::default(), &Filter::default(),
&RoomNetwork::Matrix, &RoomNetwork::Matrix,
) )
.await?; .await
.map_err(|e| {
warn!("Failed to return our /publicRooms: {e}");
Error::BadRequest(ErrorKind::Unknown, "Failed to return this server's public room list.")
})?;
Ok(get_public_rooms::v3::Response { Ok(get_public_rooms::v3::Response {
chunk: response.chunk, chunk: response.chunk,

View file

@ -265,6 +265,7 @@ where
} }
}, },
AuthScheme::None => match parts.uri.path() { AuthScheme::None => match parts.uri.path() {
// TOOD: can we do a better check here?
// allow_public_room_directory_without_auth // allow_public_room_directory_without_auth
"/_matrix/client/v3/publicRooms" | "/_matrix/client/r0/publicRooms" => { "/_matrix/client/v3/publicRooms" | "/_matrix/client/r0/publicRooms" => {
if !services() if !services()

View file

@ -33,7 +33,7 @@ use ruma::{
}, },
OutgoingResponse, OutgoingResponse,
}, },
directory::{Filter, RoomNetwork}, directory::Filter,
events::{ events::{
receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType}, receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType},
room::{ room::{
@ -162,7 +162,11 @@ pub async fn get_public_rooms_filtered_route(
&body.filter, &body.filter,
&body.room_network, &body.room_network,
) )
.await?; .await
.map_err(|e| {
warn!("Failed to return our /publicRooms: {e}");
Error::BadRequest(ErrorKind::Unknown, "Failed to return this server's public room list.")
})?;
Ok(get_public_rooms_filtered::v1::Response { Ok(get_public_rooms_filtered::v1::Response {
chunk: response.chunk, chunk: response.chunk,
@ -190,9 +194,13 @@ pub async fn get_public_rooms_route(
body.limit, body.limit,
body.since.as_deref(), body.since.as_deref(),
&Filter::default(), &Filter::default(),
&RoomNetwork::Matrix, &body.room_network,
) )
.await?; .await
.map_err(|e| {
warn!("Failed to return our /publicRooms: {e}");
Error::BadRequest(ErrorKind::Unknown, "Failed to return this server's public room list.")
})?;
Ok(get_public_rooms::v1::Response { Ok(get_public_rooms::v1::Response {
chunk: response.chunk, chunk: response.chunk,