fix(webdav): preserve correct status codes for file rename/move failures

When file or folder rename/move operations failed in WebDAV handlers,
all errors were incorrectly converted to HTTP 500 Internal Server Error
using AppError::internal_error(). This masked specific error types:

- AlreadyExists errors should return 409 CONFLICT
- NotFound errors should return 404 NOT FOUND
- AccessDenied errors should return 403 FORBIDDEN

Changed error handling to use AppError::from() which preserves the
original DomainError type and maps to appropriate HTTP status codes.

Fixes handling of incorrect status code for file rename failure.
This commit is contained in:
BillionClaw
2026-03-17 16:29:21 +08:00
parent d1699357d8
commit 3c48aa1e6f
+7 -19
View File
@@ -1236,9 +1236,7 @@ async fn handle_move(
folder_service
.move_folder(&folder.id, move_dto, user.id)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to move folder: {}", e))
})?;
.map_err(AppError::from)?;
if folder.name != dest_folder_name {
let rename_dto = crate::application::dtos::folder_dto::RenameFolderDto {
@@ -1247,9 +1245,7 @@ async fn handle_move(
folder_service
.rename_folder(&folder.id, rename_dto, user.id)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to rename folder: {}", e))
})?;
.map_err(AppError::from)?;
}
}
Ok(ResolvedResource::File(file)) => {
@@ -1283,17 +1279,13 @@ async fn handle_move(
file_management_service
.move_file(&file.id, Some(dest_parent_path.to_string()))
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to move file: {}", e))
})?;
.map_err(AppError::from)?;
}
if file.name != dest_filename {
file_management_service
.rename_file(&file.id, dest_filename)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to rename file: {}", e))
})?;
.map_err(AppError::from)?;
}
}
Err(_) => {
@@ -1354,9 +1346,7 @@ async fn handle_move(
folder_service
.rename_folder(&folder.id, rename_dto, user.id)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to rename folder: {}", e))
})?;
.map_err(AppError::from)?;
}
} else {
let file = file_retrieval_service
@@ -1396,15 +1386,13 @@ async fn handle_move(
file_management_service
.move_file(&file.id, Some(dest_parent_path.to_string()))
.await
.map_err(|e| AppError::internal_error(format!("Failed to move file: {}", e)))?;
.map_err(AppError::from)?;
}
if file.name != dest_filename {
file_management_service
.rename_file(&file.id, dest_filename)
.await
.map_err(|e| {
AppError::internal_error(format!("Failed to rename file: {}", e))
})?;
.map_err(AppError::from)?;
}
}
}