mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-06-04 22:28:02 +02:00
refactor: better error handling
This commit is contained in:
@@ -34,7 +34,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -62,7 +64,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -85,7 +89,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -109,7 +115,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -133,7 +141,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -148,7 +158,11 @@ impl SyncClient {
|
||||
data: &[u8],
|
||||
content_type: Option<&str>,
|
||||
) -> SyncResult<()> {
|
||||
let mut req = self.client.put(presigned_url).body(data.to_vec());
|
||||
let mut req = self
|
||||
.client
|
||||
.put(presigned_url)
|
||||
.header("Content-Length", data.len().to_string())
|
||||
.body(data.to_vec());
|
||||
|
||||
if let Some(ct) = content_type {
|
||||
req = req.header("Content-Type", ct);
|
||||
@@ -214,7 +228,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -242,7 +258,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
@@ -270,7 +288,9 @@ impl SyncClient {
|
||||
.map_err(|e| SyncError::NetworkError(e.to_string()))?;
|
||||
|
||||
if response.status().is_client_error() {
|
||||
return Err(SyncError::AuthError("Invalid or missing token".to_string()));
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(SyncError::AuthError(format!("({status}) {body}")));
|
||||
}
|
||||
|
||||
response
|
||||
|
||||
@@ -1146,6 +1146,23 @@ pub async fn set_profile_sync_enabled(
|
||||
);
|
||||
}
|
||||
|
||||
// Report updated sync-enabled profile count to the cloud backend
|
||||
if crate::cloud_auth::CLOUD_AUTH.is_logged_in().await {
|
||||
let sync_count = profile_manager
|
||||
.list_profiles()
|
||||
.map(|profiles| profiles.iter().filter(|p| p.sync_enabled).count())
|
||||
.unwrap_or(0);
|
||||
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = crate::cloud_auth::CLOUD_AUTH
|
||||
.report_sync_profile_count(sync_count as i64)
|
||||
.await
|
||||
{
|
||||
log::warn!("Failed to report sync profile count: {e}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,10 @@ pub const DEFAULT_EXCLUDE_PATTERNS: &[&str] = &[
|
||||
"blob_storage/**",
|
||||
"*.log",
|
||||
"*.tmp",
|
||||
"LOG",
|
||||
"LOG.old",
|
||||
"LOCK",
|
||||
"**/LOG",
|
||||
"**/LOG.old",
|
||||
"**/LOCK",
|
||||
"**/*-journal",
|
||||
".donut-sync/**",
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user