melib/error:Add ErrorKind::Timeout

Timeout errors lead to automatic restart of connections without
bothering the user about the details, compared to actual network errors.
master
Manos Pitsidianakis 2020-08-26 20:01:39 +03:00
parent 25b325dbda
commit f02dde46da
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 21 additions and 9 deletions

View File

@ -195,7 +195,7 @@ pub async fn timeout<O>(dur: std::time::Duration, f: impl Future<Output = O>) ->
Either::Left((out, _)) => Ok(out),
Either::Right(_) => {
Err(crate::error::MeliError::new("Timed out.")
.set_kind(crate::error::ErrorKind::Network))
.set_kind(crate::error::ErrorKind::Timeout))
}
}
}

View File

@ -39,6 +39,7 @@ pub enum ErrorKind {
None,
Authentication,
Network,
Timeout,
}
impl ErrorKind {
@ -49,6 +50,13 @@ impl ErrorKind {
}
}
pub fn is_timeout(&self) -> bool {
match self {
ErrorKind::Timeout => true,
_ => false,
}
}
pub fn is_authentication(&self) -> bool {
match self {
ErrorKind::Authentication => true,

View File

@ -1974,14 +1974,18 @@ impl Account {
let r = channel.try_recv().unwrap();
debug!("JobRequest::Watch {:?}", r);
if let Some(Err(err)) = r {
//TODO: relaunch watch job with ratelimit for failure
self.sender
.send(ThreadEvent::UIEvent(UIEvent::Notification(
Some(format!("{}: watch thread failed", &self.name)),
err.to_string(),
Some(crate::types::NotificationType::ERROR),
)))
.expect("Could not send event on main channel");
if err.kind.is_timeout() {
self.watch();
} else {
//TODO: relaunch watch job with ratelimit for failure
self.sender
.send(ThreadEvent::UIEvent(UIEvent::Notification(
Some(format!("{}: watch thread failed", &self.name)),
err.to_string(),
Some(crate::types::NotificationType::ERROR),
)))
.expect("Could not send event on main channel");
}
}
}
JobRequest::Generic {