aboutsummaryrefslogtreecommitdiff
path: root/src/api/common/common_error.rs
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-31 18:34:57 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-01-31 18:34:57 +0100
commit84f1db91c4e53a8d0c037fd01adb695fd9400ed5 (patch)
tree9f80c50a55bcde668f487957b88cf00e682e4190 /src/api/common/common_error.rs
parent9fa20d45bebab2a3f66b9721c3643dbd607d944d (diff)
downloadgarage-84f1db91c4e53a8d0c037fd01adb695fd9400ed5.tar.gz
garage-84f1db91c4e53a8d0c037fd01adb695fd9400ed5.zip
fix things up
Diffstat (limited to 'src/api/common/common_error.rs')
-rw-r--r--src/api/common/common_error.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/api/common/common_error.rs b/src/api/common/common_error.rs
index 1e3f9feb..597a3511 100644
--- a/src/api/common/common_error.rs
+++ b/src/api/common/common_error.rs
@@ -57,6 +57,35 @@ pub enum CommonError {
InvalidBucketName(String),
}
+#[macro_export]
+macro_rules! commonErrorDerivative {
+ ( $error_struct: ident ) => {
+ impl From<garage_util::error::Error> for $error_struct {
+ fn from(err: garage_util::error::Error) -> Self {
+ Self::Common(CommonError::InternalError(err))
+ }
+ }
+ impl From<http::Error> for $error_struct {
+ fn from(err: http::Error) -> Self {
+ Self::Common(CommonError::Http(err))
+ }
+ }
+ impl From<hyper::Error> for $error_struct {
+ fn from(err: hyper::Error) -> Self {
+ Self::Common(CommonError::Hyper(err))
+ }
+ }
+ impl From<hyper::header::ToStrError> for $error_struct {
+ fn from(err: hyper::header::ToStrError) -> Self {
+ Self::Common(CommonError::InvalidHeader(err))
+ }
+ }
+ impl CommonErrorDerivative for $error_struct {}
+ };
+}
+
+pub use commonErrorDerivative;
+
impl CommonError {
pub fn http_status_code(&self) -> StatusCode {
match self {