mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 23:49:53 +08:00
chore: 修改 error 判断,考虑 chain (#291)
This commit is contained in:
@@ -26,21 +26,27 @@ impl From<Result<ExecutionStatus>> for ExecutionStatus {
|
|||||||
match res {
|
match res {
|
||||||
Ok(status) => status,
|
Ok(status) => status,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if let Some(error) = err.downcast_ref::<io::Error>() {
|
for cause in err.chain() {
|
||||||
let error_kind = error.kind();
|
if let Some(io_err) = cause.downcast_ref::<io::Error>() {
|
||||||
if error_kind == io::ErrorKind::PermissionDenied
|
// 权限错误
|
||||||
|| (error_kind == io::ErrorKind::Other
|
if io_err.kind() == io::ErrorKind::PermissionDenied {
|
||||||
&& error.get_ref().is_some_and(|e| {
|
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::<reqwest::Error>()
|
e.downcast_ref::<reqwest::Error>()
|
||||||
.is_some_and(|e| e.is_decode() || e.is_body() || e.is_timeout())
|
.is_some_and(|e| is_ignored_reqwest_error(e))
|
||||||
}))
|
})
|
||||||
{
|
{
|
||||||
return ExecutionStatus::Ignored(err);
|
return ExecutionStatus::Ignored(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// 未包裹的 reqwest::Error
|
||||||
if let Some(error) = err.downcast_ref::<reqwest::Error>() {
|
if let Some(error) = cause.downcast_ref::<reqwest::Error>() {
|
||||||
if error.is_decode() || error.is_body() || error.is_timeout() {
|
if is_ignored_reqwest_error(error) {
|
||||||
return ExecutionStatus::Ignored(err);
|
return ExecutionStatus::Ignored(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExecutionStatus::Failed(err)
|
ExecutionStatus::Failed(err)
|
||||||
@@ -48,3 +54,7 @@ impl From<Result<ExecutionStatus>> for ExecutionStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_ignored_reqwest_error(err: &reqwest::Error) -> bool {
|
||||||
|
err.is_decode() || err.is_body() || err.is_timeout()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user