diff --git a/melib/src/connections.rs b/melib/src/connections.rs index 2abbf1a8..8fdebe69 100644 --- a/melib/src/connections.rs +++ b/melib/src/connections.rs @@ -195,7 +195,7 @@ pub async fn timeout(dur: std::time::Duration, f: impl Future) -> 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)) } } } diff --git a/melib/src/error.rs b/melib/src/error.rs index 5e4c925e..95f1f8e7 100644 --- a/melib/src/error.rs +++ b/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, diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index dbb68b5f..d4fecd9c 100644 --- a/src/conf/accounts.rs +++ b/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 {