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 --- Cargo.lock | 1 + src/api/api_server.rs | 16 +++++++++------- src/api/helpers.rs | 10 +++++----- src/api/lib.rs | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b516664..6382d035 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,6 +429,7 @@ dependencies = [ "bytes 0.4.12", "chrono", "crypto-mac", + "err-derive", "futures", "futures-util", "garage_model 0.1.1", 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