From ec16d166f940f59098ae5cc0c0b3d8298f1bcc78 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 13 May 2022 15:43:44 +0200 Subject: Separate error types for k2v and signature --- src/api/s3/api_server.rs | 3 ++- src/api/s3/error.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/api/s3') diff --git a/src/api/s3/api_server.rs b/src/api/s3/api_server.rs index 6b565fd0..4df9ee6d 100644 --- a/src/api/s3/api_server.rs +++ b/src/api/s3/api_server.rs @@ -119,7 +119,8 @@ impl ApiHandler for S3ApiServer { return handle_post_object(garage, req, bucket_name.unwrap()).await; } if let Endpoint::Options = endpoint { - return handle_options_s3api(garage, &req, bucket_name).await; + return handle_options_s3api(garage, &req, bucket_name).await + .map_err(Error::from); } let (api_key, mut content_sha256) = check_payload_signature(&garage, "s3", &req).await?; diff --git a/src/api/s3/error.rs b/src/api/s3/error.rs index 3cb97019..a0c4703c 100644 --- a/src/api/s3/error.rs +++ b/src/api/s3/error.rs @@ -11,6 +11,7 @@ use crate::common_error::CommonError; pub use crate::common_error::{OkOrBadRequest, OkOrInternalError}; use crate::generic_server::ApiError; use crate::s3::xml as s3_xml; +use crate::signature::error::Error as SignatureError; /// Errors of this crate #[derive(Debug, Error)] @@ -134,6 +135,18 @@ impl From for Error { } } +impl From for Error { + fn from(err: SignatureError) -> Self { + match err { + SignatureError::CommonError(c) => Self::CommonError(c), + SignatureError::AuthorizationHeaderMalformed(c) => Self::AuthorizationHeaderMalformed(c), + SignatureError::Forbidden(f) => Self::Forbidden(f), + SignatureError::InvalidUtf8Str(i) => Self::InvalidUtf8Str(i), + SignatureError::InvalidHeader(h) => Self::InvalidHeader(h), + } + } +} + impl From for Error { fn from(err: multer::Error) -> Self { Self::bad_request(err) -- cgit v1.2.3