Clean up code and add expect for get_infotype inner JSON data

This commit is contained in:
Evie Viau 2022-02-17 22:16:25 -05:00
parent fb05f0e141
commit 9531b3f138
No known key found for this signature in database
GPG key ID: DBCFB51C41FF87FF

View file

@ -115,12 +115,17 @@ pub struct InfoMessage {
/// Info data, varies depending on InfoType
data: InfoData
}
pub fn get_infotype(msg: Message) -> Result<(InfoType, InfoData), ()> {
let message_json: Result<Value, serde_json::Error> = serde_json::from_str(msg.to_text().expect("Failed to convert message to str!"));
let message_json: Result<Value, serde_json::Error> = serde_json::from_str(
msg.to_text().expect("Failed to convert message to str!")
);
if message_json.is_ok() {
// TODO: Maybe find a better way?
let info_data: InfoMessage = serde_json::from_value(message_json.unwrap().get("d").unwrap().clone()).unwrap();
let info_data: InfoMessage = serde_json::from_value(
message_json.unwrap().get("d").unwrap().clone()
).expect("Failed to get inner data for InfoData!");
Ok((info_data._type, info_data.data))
} else {