Fixing crash on unknown op type.

- Fixes #251
This commit is contained in:
Dessalines 2019-08-30 13:33:20 -07:00
parent 9274348040
commit 99319800fc

View file

@ -233,14 +233,6 @@ impl Handler<Connect> for ChatServer {
}); });
} }
// for (k,v) in &self.rate_limits {
// println!("{}: {:?}", k,v);
// }
// auto join session to Main room
// self.rooms.get_mut(&"Main".to_owned()).unwrap().insert(id);
// send id back
id id
} }
} }
@ -285,7 +277,10 @@ fn parse_json_message(chat: &mut ChatServer, msg: StandardMessage) -> Result<Str
let json: Value = serde_json::from_str(&msg.msg)?; let json: Value = serde_json::from_str(&msg.msg)?;
let data = &json["data"].to_string(); let data = &json["data"].to_string();
let op = &json["op"].as_str().unwrap(); let op = &json["op"].as_str().ok_or(APIError {
op: "Unknown op type".to_string(),
message: format!("Unknown op type"),
})?;
let user_operation: UserOperation = UserOperation::from_str(&op)?; let user_operation: UserOperation = UserOperation::from_str(&op)?;