fix: return 404 when joining non-existent room

Fixes #1443.
This commit is contained in:
éźera
2026-03-26 18:52:03 -05:00
committed by ezera
parent fcfa7b8bef
commit 67d8d72506
3 changed files with 18 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
Fixed error 500 when joining non-existent rooms. Contributed by @ezera.
+9
View File
@@ -785,6 +785,15 @@ async fn join_room_by_id_helper_local(
};
if servers.is_empty() || servers.len() == 1 && services.globals.server_is_ours(&servers[0]) {
if !services.rooms.metadata.exists(room_id).await {
return Err!(Request(
Unknown(
"Room was not found locally and no servers were found to help us discover it"
),
NOT_FOUND
));
}
return Err(error);
}
+8
View File
@@ -77,6 +77,14 @@ macro_rules! err {
)
};
(Request($variant:ident($($args:tt)+), $status_code:ident)) => {
$crate::error::Error::Request(
$crate::ruma::api::client::error::ErrorKind::$variant,
$crate::format_maybe!($($args)+),
$crate::http::StatusCode::$status_code,
)
};
(Config($item:literal, $($args:tt)+)) => {{
let mut buf = String::new();
$crate::error::Error::Config($item, $crate::err_log!(buf, error, config = %$item, $($args)+))