Merge pull request #589 from EdouardVanbelle/fix/caldav-carddav-error-mapping

This commit is contained in:
Dionisio Pozo
2026-07-14 23:12:11 +02:00
committed by GitHub
3 changed files with 212 additions and 40 deletions
+14 -20
View File
@@ -248,7 +248,7 @@ async fn handle_propfind(
calendar_service
.list_my_calendars(user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to list calendars: {}", e)))?
.map_err(AppError::from)?
};
let base_href = "/caldav/";
@@ -364,9 +364,7 @@ async fn handle_propfind(
let calendars = calendar_service
.list_my_calendars(user.id)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to list calendars: {}", e))
})?;
.map_err(AppError::from)?;
let base_href = &format!("/caldav/{}/", first_segment);
let mut response_body = Vec::new();
@@ -448,7 +446,7 @@ async fn handle_propfind(
let event = calendar_service
.get_event_by_ical_uid(calendar_id, ical_uid, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to look up event: {}", e)))?
.map_err(AppError::from)?
.ok_or_else(|| AppError::not_found(format!("Event not found: {}", ical_uid)))?;
let base_href = &format!("/caldav/{}/", calendar_id);
@@ -505,16 +503,12 @@ async fn handle_report(
calendar_service
.get_events_in_range(calendar_id, *start, *end, user.id)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to query events: {}", e))
})?
.map_err(AppError::from)?
} else {
calendar_service
.list_events(calendar_id, None, None, user.id)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to list events: {}", e))
})?
.map_err(AppError::from)?
}
}
CalDavReportType::CalendarMultiget { hrefs, .. } => {
@@ -529,12 +523,12 @@ async fn handle_report(
calendar_service
.get_events_by_ical_uids(calendar_id, &uids, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to fetch events: {}", e)))?
.map_err(AppError::from)?
}
CalDavReportType::SyncCollection { .. } => calendar_service
.list_events(calendar_id, None, None, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to list events: {}", e)))?,
.map_err(AppError::from)?,
};
let base_href = &format!("/caldav/{}/", calendar_id);
@@ -693,12 +687,12 @@ async fn handle_get(
let events = calendar_service
.list_events(calendar_id, None, None, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to list events: {}", e)))?;
.map_err(AppError::from)?;
let calendar = calendar_service
.get_calendar(calendar_id, user.id)
.await
.map_err(|e| AppError::not_found(format!("Calendar not found: {}", e)))?;
.map_err(AppError::from)?;
let ical = generate_full_calendar_ical(&calendar.name, &events);
@@ -716,7 +710,7 @@ async fn handle_get(
let event = calendar_service
.get_event_by_ical_uid(calendar_id, ical_uid, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to look up event: {}", e)))?
.map_err(AppError::from)?
.ok_or_else(|| AppError::not_found(format!("Event not found: {}", ical_uid)))?;
let ical = generate_event_ical(&event);
@@ -809,7 +803,7 @@ async fn handle_delete(
calendar_service
.delete_calendar(calendar_id, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to delete calendar: {}", e)))?;
.map_err(AppError::from)?;
} else {
let event_file = parts[1];
let ical_uid = event_file.trim_end_matches(".ics");
@@ -818,13 +812,13 @@ async fn handle_delete(
let event = calendar_service
.get_event_by_ical_uid(calendar_id, ical_uid, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to look up event: {}", e)))?
.map_err(AppError::from)?
.ok_or_else(|| AppError::not_found(format!("Event not found: {}", ical_uid)))?;
calendar_service
.delete_event(&event.id, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to delete event: {}", e)))?;
.map_err(AppError::from)?;
}
Ok(Response::builder()
@@ -881,7 +875,7 @@ async fn handle_proppatch(
calendar_service
.update_calendar(calendar_id, update, user.id)
.await
.map_err(|e| AppError::internal_error(format!("Failed to update calendar: {}", e)))?;
.map_err(AppError::from)?;
}
let mut results = Vec::new();
+12 -20
View File
@@ -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();