Raise 404 when room doesn't exist
Raise 404 "Room not found" when changing or accessing room visibility settings (`GET` and `PUT /_matrix/client/r0/directory/list/room/{roomId}`). See issue #290
This commit is contained in:
parent
2627ca5e3d
commit
6fd39ae174
1 changed files with 17 additions and 0 deletions
|
@ -85,6 +85,14 @@ pub async fn set_room_visibility_route(
|
|||
) -> Result<set_room_visibility::v3::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
if !db.rooms.exists(&body.room_id)? {
|
||||
// Return 404 if the room doesn't exist
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Room not found",
|
||||
));
|
||||
}
|
||||
|
||||
match &body.visibility {
|
||||
room::Visibility::Public => {
|
||||
services().rooms.directory.set_public(&body.room_id)?;
|
||||
|
@ -108,6 +116,15 @@ pub async fn set_room_visibility_route(
|
|||
pub async fn get_room_visibility_route(
|
||||
body: Ruma<get_room_visibility::v3::IncomingRequest>,
|
||||
) -> Result<get_room_visibility::v3::Response> {
|
||||
|
||||
if !db.rooms.exists(&body.room_id)? {
|
||||
// Return 404 if the room doesn't exist
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Room not found",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(get_room_visibility::v3::Response {
|
||||
visibility: if services().rooms.directory.is_public_room(&body.room_id)? {
|
||||
room::Visibility::Public
|
||||
|
|
Loading…
Add table
Reference in a new issue