From 87fd432527bcd9f442bd8228bb81cc330123a7f6 Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Sat, 25 Jul 2020 15:48:12 -0400 Subject: [PATCH] Refactor account_data to be more similar to other endpoints --- src/client_server.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/client_server.rs b/src/client_server.rs index f13d6fd..9676f7b 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -589,18 +589,19 @@ pub fn get_global_account_data_route( ) -> ConduitResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); - db.account_data + let event = db + .account_data .get( None, user_id, &EventType::try_from(&body.event_type).expect("EventType::try_from can never fail"), )? - .and_then(|ev| { - serde_json::from_str(ev.json().get()) - .map(|data| get_global_account_data::Response { account_data: data }.into()) - .ok() - }) - .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found.")) + .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; + + let data = serde_json::from_str(event.json().get()) + .map_err(|_| Error::bad_database("Invalid account data event in db."))?; + + Ok(get_global_account_data::Response { account_data: data }.into()) } #[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "")]