error handling

This commit is contained in:
2025-10-29 11:14:19 +01:00
parent ac27a9ab36
commit ee8955574f
10 changed files with 102 additions and 36 deletions
+16 -9
View File
@@ -47,6 +47,7 @@ use crate::schema::{
use crate::state::AppState;
use crate::utils::{
db::{no_content, validate_bulk_ids, IntoJsonResponse},
error::StorageResultExt,
http::inline_content_disposition,
json::{classify_nullable, NullableValue},
storage_paths::document_version_object_key,
@@ -412,7 +413,10 @@ pub async fn list_documents(
let ids = quickwit_search(endpoint, index, tenant_id, query_str)
.await
.map_err(|err| AppError::internal(format!("quickwit search failed: {err}")))?;
.map_err(|err| {
error!(error = ?err, "quickwit search failed");
AppError::internal("quickwit search failed")
})?;
if ids.is_empty() {
return Ok(Json(vec![]));
@@ -913,7 +917,10 @@ pub async fn request_document_assets(
}),
None,
)
.map_err(|err| AppError::internal(format!("failed to enqueue analyze job: {err}")))?;
.map_err(|err| {
error!(error = ?err, "failed to enqueue analyze job");
AppError::internal("failed to enqueue analyze job")
})?;
Ok(StatusCode::ACCEPTED)
}
@@ -959,7 +966,10 @@ pub async fn reanalyze_selected_documents(
}),
None,
)
.map_err(|err| AppError::internal(format!("failed to enqueue analyze job: {err}")))?;
.map_err(|err| {
error!(error = ?err, "failed to enqueue analyze job");
AppError::internal("failed to enqueue analyze job")
})?;
queued += 1;
}
@@ -1048,7 +1058,7 @@ pub async fn get_document_asset(
Duration::from_secs(PRESIGNED_URL_EXPIRY_SECONDS),
)
.await
.map_err(|err| AppError::internal(format!("failed to generate asset URL: {err}")))?;
.storage_context("failed to generate asset URL")?;
object_responses.push(to_asset_object_response(
object,
@@ -1178,7 +1188,7 @@ pub async fn download_with_token(
Duration::from_secs(PRESIGNED_URL_EXPIRY_SECONDS),
)
.await
.map_err(|err| AppError::internal(format!("failed to generate download URL: {err}")))?;
.storage_context("failed to generate download URL")?;
Ok(axum::response::Redirect::temporary(&presigned_url))
}
@@ -2035,10 +2045,7 @@ async fn process_upload(
content_disposition.clone(),
)
.await
.map_err(|err| {
error!(error = %err, key = %s3_key, "failed to store document");
AppError::internal(format!("failed to store document: {err}"))
})?;
.storage_context("failed to store document")?;
let metadata_value = if metadata.is_null() {
Value::Object(Default::default())