aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3/cors.rs
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-29 19:14:34 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-01-29 19:14:34 +0100
commit9f3c7c3720d323bc9df3892197e6da5d89d1b84a (patch)
tree8e1abf81071116f71a3c969a7d5dfcf43d8c1703 /src/api/s3/cors.rs
parenta1d081ee840b1727ba1b3f430638a1296738283e (diff)
downloadgarage-9f3c7c3720d323bc9df3892197e6da5d89d1b84a.tar.gz
garage-9f3c7c3720d323bc9df3892197e6da5d89d1b84a.zip
api: better handling of helper errors to distinguish error codes
Diffstat (limited to 'src/api/s3/cors.rs')
-rw-r--r--src/api/s3/cors.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/api/s3/cors.rs b/src/api/s3/cors.rs
index 173b7ffe..32dcc0d5 100644
--- a/src/api/s3/cors.rs
+++ b/src/api/s3/cors.rs
@@ -1,6 +1,7 @@
-use quick_xml::de::from_reader;
use std::sync::Arc;
+use quick_xml::de::from_reader;
+
use http::header::{
ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN,
ACCESS_CONTROL_EXPOSE_HEADERS, ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD,
@@ -14,7 +15,7 @@ use http_body_util::BodyExt;
use serde::{Deserialize, Serialize};
-use crate::common_error::CommonError;
+use crate::common_error::{helper_error_as_internal, CommonError};
use crate::helpers::*;
use crate::s3::api_server::{ReqBody, ResBody};
use crate::s3::error::*;
@@ -116,9 +117,16 @@ pub async fn handle_options_api(
// OPTIONS calls are not auhtenticated).
if let Some(bn) = bucket_name {
let helper = garage.bucket_helper();
- let bucket_id = helper.resolve_global_bucket_name(&bn).await?;
+ let bucket_id = helper
+ .resolve_global_bucket_name(&bn)
+ .await
+ .map_err(helper_error_as_internal)?;
if let Some(id) = bucket_id {
- let bucket = garage.bucket_helper().get_existing_bucket(id).await?;
+ let bucket = garage
+ .bucket_helper()
+ .get_existing_bucket(id)
+ .await
+ .map_err(helper_error_as_internal)?;
let bucket_params = bucket.state.into_option().unwrap();
handle_options_for_bucket(req, &bucket_params)
} else {