Separate error types for k2v and signature

This commit is contained in:
Alex Auvolat
2022-05-13 15:43:44 +02:00
parent 7a5d329e49
commit ec16d166f9
14 changed files with 203 additions and 13 deletions
+2 -1
View File
@@ -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?;
+13
View File
@@ -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<HelperError> for Error {
}
}
impl From<SignatureError> 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<multer::Error> for Error {
fn from(err: multer::Error) -> Self {
Self::bad_request(err)