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.memfd
parent
25b325dbda
commit
f02dde46da
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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…
Reference in New Issue