diff --git a/Cargo.toml b/Cargo.toml index b47f2e33..1daa9f8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,7 +98,7 @@ httpdate = "1.0" http-range = "0.1" http-body-util = "0.1" hyper = { version = "1.0", features = ["server", "http1"] } -hyper-util = { verion = "0.1", features = [ "full" ]} +hyper-util = { version = "0.1", features = [ "full" ] } multer = "3.0" percent-encoding = "2.2" roxmltree = "0.19" 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); - 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 { // =============== body helpers ================= pub type EmptyBody = http_body_util::Empty; -pub type BytesBody = FullBody; +pub type ErrorBody = FullBody; pub type BoxBody = http_body_util::combinators::BoxBody; pub fn string_body(s: String) -> BoxBody { @@ -156,8 +156,8 @@ pub fn bytes_body(b: bytes::Bytes) -> BoxBody { pub fn empty_body() -> BoxBody { 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(req: Request) -> Result 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) } }