aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/admin/error.rs6
-rw-r--r--src/api/generic_server.rs4
-rw-r--r--src/api/helpers.rs6
-rw-r--r--src/api/k2v/error.rs4
-rw-r--r--src/api/s3/error.rs4
5 files changed, 12 insertions, 12 deletions
diff --git a/src/api/admin/error.rs b/src/api/admin/error.rs
index 011c903f..2668b42d 100644
--- a/src/api/admin/error.rs
+++ b/src/api/admin/error.rs
@@ -7,7 +7,7 @@ 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::{BytesBody, CustomApiErrorBody};
+use crate::helpers::*;
/// Errors of this crate
#[derive(Debug, Error)]
@@ -65,7 +65,7 @@ impl ApiError for Error {
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
}
- fn http_body(&self, garage_region: &str, path: &str) -> BytesBody {
+ fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
let error = CustomApiErrorBody {
code: self.code().to_string(),
message: format!("{}", self),
@@ -81,6 +81,6 @@ impl ApiError for Error {
"#
.into()
});
- BytesBody::from(bytes::Bytes::from(error_str.into_bytes()))
+ error_body(error_str)
}
}
diff --git a/src/api/generic_server.rs b/src/api/generic_server.rs
index e3005f8a..20d70833 100644
--- a/src/api/generic_server.rs
+++ b/src/api/generic_server.rs
@@ -30,7 +30,7 @@ use garage_util::forwarded_headers;
use garage_util::metrics::{gen_trace_id, RecordDuration};
use garage_util::socket_address::UnixOrTCPSocketAddress;
-use crate::helpers::{BoxBody, BytesBody};
+use crate::helpers::{BoxBody, ErrorBody};
pub(crate) trait ApiEndpoint: Send + Sync + 'static {
fn name(&self) -> &'static str;
@@ -40,7 +40,7 @@ pub(crate) trait ApiEndpoint: Send + Sync + 'static {
pub trait ApiError: std::error::Error + Send + Sync + 'static {
fn http_status_code(&self) -> StatusCode;
fn add_http_headers(&self, header_map: &mut HeaderMap<HeaderValue>);
- fn http_body(&self, garage_region: &str, path: &str) -> BytesBody;
+ fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody;
}
#[async_trait]
diff --git a/src/api/helpers.rs b/src/api/helpers.rs
index 57aa1ea1..66f4c465 100644
--- a/src/api/helpers.rs
+++ b/src/api/helpers.rs
@@ -144,7 +144,7 @@ pub fn key_after_prefix(pfx: &str) -> Option<String> {
// =============== body helpers =================
pub type EmptyBody = http_body_util::Empty<bytes::Bytes>;
-pub type BytesBody = FullBody<bytes::Bytes>;
+pub type ErrorBody = FullBody<bytes::Bytes>;
pub type BoxBody<E> = http_body_util::combinators::BoxBody<bytes::Bytes, E>;
pub fn string_body<E>(s: String) -> BoxBody<E> {
@@ -156,8 +156,8 @@ pub fn bytes_body<E>(b: bytes::Bytes) -> BoxBody<E> {
pub fn empty_body<E>() -> BoxBody<E> {
BoxBody::new(http_body_util::Empty::new().map_err(|_| unreachable!()))
}
-pub fn string_bytes_body(s: String) -> BytesBody {
- BytesBody::from(bytes::Bytes::from(s.into_bytes()))
+pub fn error_body(s: String) -> ErrorBody {
+ ErrorBody::from(bytes::Bytes::from(s.into_bytes()))
}
pub async fn parse_json_body<T, B, E>(req: Request<B>) -> Result<T, E>
diff --git a/src/api/k2v/error.rs b/src/api/k2v/error.rs
index 72e712bf..16479227 100644
--- a/src/api/k2v/error.rs
+++ b/src/api/k2v/error.rs
@@ -94,7 +94,7 @@ impl ApiError for Error {
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
}
- fn http_body(&self, garage_region: &str, path: &str) -> BytesBody {
+ fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
let error = CustomApiErrorBody {
code: self.code().to_string(),
message: format!("{}", self),
@@ -110,6 +110,6 @@ impl ApiError for Error {
"#
.into()
});
- string_bytes_body(error_str)
+ error_body(error_str)
}
}
diff --git a/src/api/s3/error.rs b/src/api/s3/error.rs
index a4d222de..f86c19a6 100644
--- a/src/api/s3/error.rs
+++ b/src/api/s3/error.rs
@@ -168,7 +168,7 @@ impl ApiError for Error {
}
}
- fn http_body(&self, garage_region: &str, path: &str) -> BytesBody {
+ fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
let error = s3_xml::Error {
code: s3_xml::Value(self.aws_code().to_string()),
message: s3_xml::Value(format!("{}", self)),
@@ -185,6 +185,6 @@ impl ApiError for Error {
"#
.into()
});
- string_bytes_body(error_str)
+ error_body(error_str)
}
}