From 8b0052d04f541d194818b2ad8994e00aba6b6781 Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 11 Nov 2020 12:09:53 +0100 Subject: Integrate with new error scheme --- src/api/api_server.rs | 16 +++++++++------- src/api/helpers.rs | 10 +++++----- src/api/lib.rs | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/api') 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, @@ -48,16 +48,18 @@ pub async fn run_api_server( Ok(()) } -async fn handler(garage: Arc, req: Request, client_addr: SocketAddr) -> Result, Infallible> { +async fn handler( + garage: Arc, + req: Request, + client_addr: SocketAddr, +) -> Result, 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, req: Request) -> Result, GarageError> { +async fn controller(garage: Arc, req: Request) -> Result, 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, Infallible>; } -impl InfallibleResult for Result, GarageError> { +impl InfallibleResult for Result, Error> { fn make_infallible(self) -> Result, 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; -- cgit v1.2.3