mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-26 16:33:44 +00:00
replace panics on unknown room versions with errors
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
c70ce49ec0
commit
5c4b8ad7a3
|
@ -147,7 +147,13 @@ pub async fn create_room_route(
|
|||
);
|
||||
}
|
||||
RoomVersionId::V11 => {} // V11 removed the "creator" key
|
||||
_ => panic!("Unexpected room version {}", room_version),
|
||||
_ => {
|
||||
warn!("Unexpected or unsupported room version {}", room_version);
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::BadJson,
|
||||
"Unexpected or unsupported room version found",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
content.insert(
|
||||
|
@ -172,7 +178,13 @@ pub async fn create_room_route(
|
|||
| RoomVersionId::V9
|
||||
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(sender_user.clone()),
|
||||
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
||||
_ => panic!("Unexpected room version {}", room_version),
|
||||
_ => {
|
||||
warn!("Unexpected or unsupported room version {}", room_version);
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::BadJson,
|
||||
"Unexpected or unsupported room version found",
|
||||
));
|
||||
}
|
||||
};
|
||||
let mut content = serde_json::from_str::<CanonicalJsonObject>(
|
||||
to_raw_value(&content)
|
||||
|
@ -673,7 +685,16 @@ pub async fn upgrade_room_route(
|
|||
// "creator" key no longer exists in V11 rooms
|
||||
create_event_content.remove("creator");
|
||||
}
|
||||
_ => panic!("Unexpected room version {}", body.new_version),
|
||||
_ => {
|
||||
warn!(
|
||||
"Unexpected or unsupported room version {}",
|
||||
body.new_version
|
||||
);
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::BadJson,
|
||||
"Unexpected or unsupported room version found",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
create_event_content.insert(
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::fmt::Write;
|
|||
use clap::{Parser, Subcommand};
|
||||
use regex::Regex;
|
||||
use ruma::{
|
||||
api::client::error::ErrorKind,
|
||||
events::{
|
||||
relation::InReplyTo,
|
||||
room::{
|
||||
|
@ -30,6 +31,7 @@ use ruma::{
|
|||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use tokio::sync::{mpsc, Mutex};
|
||||
use tracing::warn;
|
||||
|
||||
use crate::{
|
||||
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
||||
|
@ -1420,7 +1422,13 @@ impl Service {
|
|||
| RoomVersionId::V9
|
||||
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(conduit_user.clone()),
|
||||
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
||||
_ => panic!("Unexpected room version {}", room_version),
|
||||
_ => {
|
||||
warn!("Unexpected or unsupported room version {}", room_version);
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::BadJson,
|
||||
"Unexpected or unsupported room version found",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
content.federate = true;
|
||||
|
|
|
@ -439,7 +439,13 @@ impl Service {
|
|||
self.redact_pdu(redact_id, pdu)?;
|
||||
}
|
||||
}
|
||||
_ => panic!("Unexpected room version {}", room_version_id),
|
||||
_ => {
|
||||
warn!("Unexpected or unsupported room version {}", room_version_id);
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::BadJson,
|
||||
"Unexpected or unsupported room version found",
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
TimelineEventType::SpaceChild => {
|
||||
|
|
Loading…
Reference in a new issue