Browse Source

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 2 years ago
parent
commit
f02dde46da
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 2
      melib/src/connections.rs
  2. 8
      melib/src/error.rs
  3. 20
      src/conf/accounts.rs

2
melib/src/connections.rs

@ -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))
}
}
}

8
melib/src/error.rs

@ -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,

20
src/conf/accounts.rs

@ -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 {

Loading…
Cancel
Save