aboutsummaryrefslogtreecommitdiff
path: root/src/api/admin/error.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-13 11:24:56 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-13 11:36:28 +0100
commitcf2af186fcc0c8f581a966454b6cd4720d3821f0 (patch)
tree37a978ba9ffb780fc828cff7b8ec93662d50884f /src/api/admin/error.rs
parentdb48dd3d6c1f9e86a62e9b8edfce2c1620bcd5f3 (diff)
parent823078b4cdaf93e09de0847c5eaa75beb7b26b7f (diff)
downloadgarage-cf2af186fcc0c8f581a966454b6cd4720d3821f0.tar.gz
garage-cf2af186fcc0c8f581a966454b6cd4720d3821f0.zip
Merge branch 'main' into next-0.10
Diffstat (limited to 'src/api/admin/error.rs')
-rw-r--r--src/api/admin/error.rs23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/api/admin/error.rs b/src/api/admin/error.rs
index ed1a07bd..2668b42d 100644
--- a/src/api/admin/error.rs
+++ b/src/api/admin/error.rs
@@ -1,13 +1,13 @@
use err_derive::Error;
use hyper::header::HeaderValue;
-use hyper::{Body, HeaderMap, StatusCode};
+use hyper::{HeaderMap, StatusCode};
pub use garage_model::helper::error::Error as HelperError;
use crate::common_error::CommonError;
pub use crate::common_error::{CommonErrorDerivative, OkOrBadRequest, OkOrInternalError};
use crate::generic_server::ApiError;
-use crate::helpers::CustomApiErrorBody;
+use crate::helpers::*;
/// Errors of this crate
#[derive(Debug, Error)]
@@ -40,18 +40,6 @@ where
impl CommonErrorDerivative for Error {}
-impl From<HelperError> for Error {
- fn from(err: HelperError) -> Self {
- match err {
- HelperError::Internal(i) => Self::Common(CommonError::InternalError(i)),
- HelperError::BadRequest(b) => Self::Common(CommonError::BadRequest(b)),
- HelperError::InvalidBucketName(n) => Self::Common(CommonError::InvalidBucketName(n)),
- HelperError::NoSuchBucket(n) => Self::Common(CommonError::NoSuchBucket(n)),
- HelperError::NoSuchAccessKey(n) => Self::NoSuchAccessKey(n),
- }
- }
-}
-
impl Error {
fn code(&self) -> &'static str {
match self {
@@ -77,14 +65,14 @@ impl ApiError for Error {
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
}
- fn http_body(&self, garage_region: &str, path: &str) -> Body {
+ fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
let error = CustomApiErrorBody {
code: self.code().to_string(),
message: format!("{}", self),
path: path.to_string(),
region: garage_region.to_string(),
};
- Body::from(serde_json::to_string_pretty(&error).unwrap_or_else(|_| {
+ let error_str = serde_json::to_string_pretty(&error).unwrap_or_else(|_| {
r#"
{
"code": "InternalError",
@@ -92,6 +80,7 @@ impl ApiError for Error {
}
"#
.into()
- }))
+ });
+ error_body(error_str)
}
}