Improve error handling for events and in general
All checks were successful
/ build-upload (push) Successful in 1m8s
All checks were successful
/ build-upload (push) Successful in 1m8s
This commit is contained in:
parent
8d1e813c0b
commit
f860fe3689
6 changed files with 114 additions and 104 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::time::Duration;
|
||||
use crate::utils::SendTextMessageTarget;
|
||||
use telnet::Event::Data;
|
||||
use telnet::Event::{Data, TimedOut};
|
||||
use telnet::Telnet;
|
||||
use crate::models::EventType;
|
||||
|
||||
|
|
@ -14,18 +15,21 @@ fn to_single_response(resp: Response) -> Response {
|
|||
}
|
||||
|
||||
fn read_part(connection: &mut Telnet) -> Result<String, String> {
|
||||
match connection.read() {
|
||||
match connection.read_timeout(Duration::new(5, 0)) {
|
||||
Ok(event) => {
|
||||
match event {
|
||||
Data(bytes) => Ok(String::from_utf8(bytes.to_vec())
|
||||
.map_err(|_| "Teamspeak returned a badly formatted models.")?),
|
||||
.map_err(|_| "Teamspeak returned an invalid response.")?),
|
||||
TimedOut => {
|
||||
Ok(String::new())
|
||||
},
|
||||
_ => {
|
||||
Err(String::from("Received unknown event from Teamspeak."))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
Err(String::from("Failed to read from Teamspeak."))
|
||||
Err(err) => {
|
||||
Err(format!("Failed to read from Teamspeak: {}", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue