diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-11-11 12:09:53 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-11-11 12:09:53 +0100 |
commit | 8b0052d04f541d194818b2ad8994e00aba6b6781 (patch) | |
tree | 91e94efa9b5674ee9aa7fa53cd3f3415b457b8c3 /src/api | |
parent | e31aa0f7dfb4c8f014ce65cdf749141d2a9fec21 (diff) | |
download | garage-feature/refactor-s3.tar.gz garage-feature/refactor-s3.zip |
Integrate with new error schemefeature/refactor-s3
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/api_server.rs | 16 | ||||
-rw-r--r-- | src/api/helpers.rs | 10 | ||||
-rw-r--r-- | src/api/lib.rs | 2 |
3 files changed, 15 insertions, 13 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs index cdf8fa78..3f65da26 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; +use std::convert::Infallible; use std::net::SocketAddr; use std::sync::Arc; -use std::convert::Infallible; use futures::future::Future; use hyper::server::conn::AddrStream; @@ -15,12 +15,12 @@ use garage_model::garage::Garage; use crate::error::*; use crate::signature::check_signature; +use crate::helpers::*; use crate::s3_copy::*; use crate::s3_delete::*; use crate::s3_get::*; use crate::s3_list::*; use crate::s3_put::*; -use crate::helpers::*; pub async fn run_api_server( garage: Arc<Garage>, @@ -48,16 +48,18 @@ pub async fn run_api_server( Ok(()) } -async fn handler(garage: Arc<Garage>, req: Request<Body>, client_addr: SocketAddr) -> Result<Response<Body>, Infallible> { +async fn handler( + garage: Arc<Garage>, + req: Request<Body>, + client_addr: SocketAddr, +) -> Result<Response<Body>, Infallible> { info!("{} {} {}", client_addr, req.method(), req.uri()); debug!("{:?}", req); - controller(garage, req) - .await - .make_infallible() + controller(garage, req).await.make_infallible() } -async fn controller(garage: Arc<Garage>, req: Request<Body>) -> Result<Response<Body>, GarageError> { +async fn controller(garage: Arc<Garage>, req: Request<Body>) -> Result<Response<Body>, Error> { let path = req.uri().path().to_string(); let path = percent_encoding::percent_decode_str(&path).decode_utf8()?; diff --git a/src/api/helpers.rs b/src/api/helpers.rs index f4d91788..b762bd3f 100644 --- a/src/api/helpers.rs +++ b/src/api/helpers.rs @@ -1,20 +1,20 @@ +use hyper::{Body, Response}; use std::convert::Infallible; use std::net::SocketAddr; -use hyper::{Body, Response}; -use garage_util::error::Error as GarageError; +use crate::error::*; pub trait InfallibleResult { fn make_infallible(self) -> Result<Response<Body>, Infallible>; } -impl InfallibleResult for Result<Response<Body>, GarageError> { +impl InfallibleResult for Result<Response<Body>, Error> { fn make_infallible(self) -> Result<Response<Body>, Infallible> { match self { Ok(x) => { - debug!("{} {:?}", x.status(), x.headers()); + debug!("{} {:?}", x.status(), x.headers()); Ok(x) - }, + } Err(e) => { let body: Body = Body::from(format!("{}\n", e)); let mut http_error = Response::new(body); diff --git a/src/api/lib.rs b/src/api/lib.rs index 7327354f..0eb64918 100644 --- a/src/api/lib.rs +++ b/src/api/lib.rs @@ -8,9 +8,9 @@ pub mod encoding; pub mod api_server; pub mod signature; +pub mod helpers; pub mod s3_copy; pub mod s3_delete; pub mod s3_get; pub mod s3_list; pub mod s3_put; -pub mod helpers; |