diff --git a/crates/bili_sync/src/error.rs b/crates/bili_sync/src/error.rs index a8f6100..4830280 100644 --- a/crates/bili_sync/src/error.rs +++ b/crates/bili_sync/src/error.rs @@ -26,21 +26,27 @@ impl From> for ExecutionStatus { match res { Ok(status) => status, Err(err) => { - if let Some(error) = err.downcast_ref::() { - let error_kind = error.kind(); - if error_kind == io::ErrorKind::PermissionDenied - || (error_kind == io::ErrorKind::Other - && error.get_ref().is_some_and(|e| { + for cause in err.chain() { + if let Some(io_err) = cause.downcast_ref::() { + // 权限错误 + if io_err.kind() == io::ErrorKind::PermissionDenied { + return ExecutionStatus::Ignored(err); + } + // 使用 io::Error 包裹的 reqwest::Error + if io_err.kind() == io::ErrorKind::Other + && io_err.get_ref().is_some_and(|e| { e.downcast_ref::() - .is_some_and(|e| e.is_decode() || e.is_body() || e.is_timeout()) - })) - { - return ExecutionStatus::Ignored(err); + .is_some_and(|e| is_ignored_reqwest_error(e)) + }) + { + return ExecutionStatus::Ignored(err); + } } - } - if let Some(error) = err.downcast_ref::() { - if error.is_decode() || error.is_body() || error.is_timeout() { - return ExecutionStatus::Ignored(err); + // 未包裹的 reqwest::Error + if let Some(error) = cause.downcast_ref::() { + if is_ignored_reqwest_error(error) { + return ExecutionStatus::Ignored(err); + } } } ExecutionStatus::Failed(err) @@ -48,3 +54,7 @@ impl From> for ExecutionStatus { } } } + +fn is_ignored_reqwest_error(err: &reqwest::Error) -> bool { + err.is_decode() || err.is_body() || err.is_timeout() +}