fix(caldav+carddav): return correct error rather 500
This commit is contained in:
@@ -254,9 +254,7 @@ async fn handle_propfind(
|
||||
addressbook_service
|
||||
.list_user_address_books(user.id)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
AppError::internal_error(format!("Failed to list address books: {}", e))
|
||||
})?
|
||||
.map_err(AppError::from)?
|
||||
};
|
||||
|
||||
let mut response_body = Vec::new();
|
||||
@@ -307,9 +305,7 @@ async fn handle_propfind(
|
||||
let address_books = addressbook_service
|
||||
.list_user_address_books(user.id)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
AppError::internal_error(format!("Failed to list address books: {}", e))
|
||||
})?;
|
||||
.map_err(AppError::from)?;
|
||||
|
||||
let user_part = path.split('/').next().unwrap_or(path);
|
||||
let base_href = format!("/carddav/{}/", user_part);
|
||||
@@ -373,7 +369,7 @@ async fn handle_propfind(
|
||||
let contact = contact_svc
|
||||
.get_contact_by_uid(address_book_id, contact_uid, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to look up contact: {}", e)))?
|
||||
.map_err(AppError::from)?
|
||||
.ok_or_else(|| {
|
||||
AppError::not_found(format!("Contact not found: {}", contact_uid))
|
||||
})?;
|
||||
@@ -432,7 +428,7 @@ async fn handle_report(
|
||||
CardDavReportType::AddressbookQuery { .. } => contact_svc
|
||||
.list_contacts(address_book_id, None, None, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to list contacts: {}", e)))?,
|
||||
.map_err(AppError::from)?,
|
||||
CardDavReportType::AddressbookMultiget { hrefs, .. } => {
|
||||
// Indexed batch lookup (`uid = ANY(...)`) — a multiget for a
|
||||
// handful of contacts must not pay for listing the whole
|
||||
@@ -445,12 +441,12 @@ async fn handle_report(
|
||||
contact_svc
|
||||
.get_contacts_by_uids(address_book_id, &uids, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to fetch contacts: {}", e)))?
|
||||
.map_err(AppError::from)?
|
||||
}
|
||||
CardDavReportType::SyncCollection { .. } => contact_svc
|
||||
.list_contacts(address_book_id, None, None, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to list contacts: {}", e)))?,
|
||||
.map_err(AppError::from)?,
|
||||
};
|
||||
|
||||
// Generate vCards
|
||||
@@ -646,7 +642,7 @@ async fn handle_get(
|
||||
let contacts = contact_svc
|
||||
.list_contacts(address_book_id, None, None, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to list contacts: {}", e)))?;
|
||||
.map_err(AppError::from)?;
|
||||
|
||||
let mut vcf_data = String::new();
|
||||
for contact in &contacts {
|
||||
@@ -666,7 +662,7 @@ async fn handle_get(
|
||||
let contact = contact_svc
|
||||
.get_contact_by_uid(address_book_id, contact_uid, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to look up contact: {}", e)))?
|
||||
.map_err(AppError::from)?
|
||||
.ok_or_else(|| AppError::not_found(format!("Contact not found: {}", contact_uid)))?;
|
||||
|
||||
let vcard = contact_to_vcard(&contact);
|
||||
@@ -704,9 +700,7 @@ async fn handle_delete(
|
||||
addressbook_service
|
||||
.delete_address_book(address_book_id, user.id)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
AppError::internal_error(format!("Failed to delete address book: {}", e))
|
||||
})?;
|
||||
.map_err(AppError::from)?;
|
||||
} else {
|
||||
// Delete contact — indexed lookup by vCard UID.
|
||||
let contact_file = parts[1];
|
||||
@@ -715,13 +709,13 @@ async fn handle_delete(
|
||||
let contact = contact_svc
|
||||
.get_contact_by_uid(address_book_id, contact_uid, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to look up contact: {}", e)))?
|
||||
.map_err(AppError::from)?
|
||||
.ok_or_else(|| AppError::not_found(format!("Contact not found: {}", contact_uid)))?;
|
||||
|
||||
contact_svc
|
||||
.delete_contact(&contact.id, user.id)
|
||||
.await
|
||||
.map_err(|e| AppError::internal_error(format!("Failed to delete contact: {}", e)))?;
|
||||
.map_err(AppError::from)?;
|
||||
}
|
||||
|
||||
Ok(Response::builder()
|
||||
@@ -779,9 +773,7 @@ async fn handle_proppatch(
|
||||
addressbook_service
|
||||
.update_address_book(address_book_id, update)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
AppError::internal_error(format!("Failed to update address book: {}", e))
|
||||
})?;
|
||||
.map_err(AppError::from)?;
|
||||
}
|
||||
|
||||
let mut results = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user