aboutsummaryrefslogtreecommitdiff
path: root/src/api/common_error.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-05 19:27:12 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-05 19:27:12 +0100
commita22bd319202f05bce4ad13072238c7ba81d518fb (patch)
tree817d90efaeaa51ea8aebaf5b25ad56c8b968dc0c /src/api/common_error.rs
parent0bb5b77530ad432e4c77f13b395fe74613812337 (diff)
downloadgarage-a22bd319202f05bce4ad13072238c7ba81d518fb.tar.gz
garage-a22bd319202f05bce4ad13072238c7ba81d518fb.zip
[dep-upgrade-202402] migration to http/hyper 1.0 for k2v api
Diffstat (limited to 'src/api/common_error.rs')
-rw-r--r--src/api/common_error.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/api/common_error.rs b/src/api/common_error.rs
index 20f9f266..4381f227 100644
--- a/src/api/common_error.rs
+++ b/src/api/common_error.rs
@@ -3,6 +3,8 @@ use hyper::StatusCode;
use garage_util::error::Error as GarageError;
+use garage_model::helper::error::Error as HelperError;
+
/// Errors of this crate
#[derive(Debug, Error)]
pub enum CommonError {
@@ -28,6 +30,10 @@ pub enum CommonError {
#[error(display = "Bad request: {}", _0)]
BadRequest(String),
+ /// The client sent a header with invalid value
+ #[error(display = "Invalid header value: {}", _0)]
+ InvalidHeader(#[error(source)] hyper::header::ToStrError),
+
// ---- SPECIFIC ERROR CONDITIONS ----
// These have to be error codes referenced in the S3 spec here:
// https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html#ErrorCodeList
@@ -64,7 +70,9 @@ impl CommonError {
CommonError::Forbidden(_) => StatusCode::FORBIDDEN,
CommonError::NoSuchBucket(_) => StatusCode::NOT_FOUND,
CommonError::BucketNotEmpty | CommonError::BucketAlreadyExists => StatusCode::CONFLICT,
- CommonError::InvalidBucketName(_) => StatusCode::BAD_REQUEST,
+ CommonError::InvalidBucketName(_) | CommonError::InvalidHeader(_) => {
+ StatusCode::BAD_REQUEST
+ }
}
}
@@ -84,6 +92,7 @@ impl CommonError {
CommonError::BucketAlreadyExists => "BucketAlreadyExists",
CommonError::BucketNotEmpty => "BucketNotEmpty",
CommonError::InvalidBucketName(_) => "InvalidBucketName",
+ CommonError::InvalidHeader(_) => "InvalidHeaderValue",
}
}
@@ -92,6 +101,18 @@ impl CommonError {
}
}
+impl From<HelperError> for CommonError {
+ fn from(err: HelperError) -> Self {
+ match err {
+ HelperError::Internal(i) => Self::InternalError(i),
+ HelperError::BadRequest(b) => Self::BadRequest(b),
+ HelperError::InvalidBucketName(n) => Self::InvalidBucketName(n),
+ HelperError::NoSuchBucket(n) => Self::NoSuchBucket(n),
+ e => Self::bad_request(format!("{}", e)),
+ }
+ }
+}
+
pub trait CommonErrorDerivative: From<CommonError> {
fn internal_error<M: ToString>(msg: M) -> Self {
Self::from(CommonError::InternalError(GarageError::Message(