refactor some additional errors
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
f51d4237c7
commit
2e3e14b045
13 changed files with 127 additions and 148 deletions
|
@ -1,18 +1,18 @@
|
|||
use conduit::{pdu::gen_event_id_canonical_json, warn, Err, Error, Result};
|
||||
use ruma::{api::client::error::ErrorKind, CanonicalJsonObject, OwnedEventId, OwnedRoomId, RoomId};
|
||||
use conduit::{debug_warn, err, pdu::gen_event_id_canonical_json, Err, Result};
|
||||
use ruma::{CanonicalJsonObject, OwnedEventId, OwnedRoomId, RoomId};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
impl super::Service {
|
||||
pub fn parse_incoming_pdu(&self, pdu: &RawJsonValue) -> Result<(OwnedEventId, CanonicalJsonObject, OwnedRoomId)> {
|
||||
let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
|
||||
warn!("Error parsing incoming event {pdu:?}: {e:?}");
|
||||
Error::BadServerResponse("Invalid PDU in server response")
|
||||
debug_warn!("Error parsing incoming event {pdu:#?}");
|
||||
err!(BadServerResponse("Error parsing incoming event {e:?}"))
|
||||
})?;
|
||||
|
||||
let room_id: OwnedRoomId = value
|
||||
.get("room_id")
|
||||
.and_then(|id| RoomId::parse(id.as_str()?).ok())
|
||||
.ok_or(Error::BadRequest(ErrorKind::InvalidParam, "Invalid room id in pdu"))?;
|
||||
.ok_or(err!(Request(InvalidParam("Invalid room id in pdu"))))?;
|
||||
|
||||
let Ok(room_version_id) = self.services.state.get_room_version(&room_id) else {
|
||||
return Err!("Server is not in room {room_id}");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue