change error handling to hopefully fix silent disconnect

This commit is contained in:
Alex Janka 2024-04-25 09:09:07 +10:00
parent e803fa4edf
commit 1d4401a556

View file

@ -311,15 +311,17 @@ impl DeviceConnection {
self.characteristics_request(true),
)
.await
.map_err(|_| HomekitError::Timeout)
.flatten_result()
{
Ok(r) => r,
Err(_) => {
Ok(r) => Ok(r),
Err(e) => {
log::warn!(
"{}failed to update characteristics",
"{}failed to update characteristics: {e:?}",
formatted_name(&self.name)
);
self.socket = None;
Err(HomekitError::Timeout)
Err(e)
}
}
}
@ -432,6 +434,24 @@ pub enum HomekitError {
NoData,
}
trait FlattenResult {
type T;
type E;
fn flatten_result(self) -> Result<Self::T, Self::E>;
}
impl<T, E> FlattenResult for Result<Result<T, E>, E> {
type T = T;
type E = E;
fn flatten_result(self) -> Result<Self::T, Self::E> {
match self {
Ok(v) => v,
Err(e) => Err(e),
}
}
}
#[derive(Debug, Error)]
pub enum ConnectionError {
#[error("http")]