From 08292b5c86eb8af9f3876ebbf3e379da3f76645d Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 6 Jul 2020 21:32:15 +0200 Subject: [PATCH] refactor HandlerError to implement From for all E: Into --- examples/diesel/src/main.rs | 19 +- examples/handlers/async_handlers/src/main.rs | 8 +- examples/handlers/form_urlencoded/src/main.rs | 4 +- examples/handlers/multipart/src/main.rs | 4 +- examples/handlers/request_data/src/main.rs | 4 +- gotham/Cargo.toml | 2 +- gotham/src/handler/assets/mod.rs | 5 +- gotham/src/handler/error.rs | 243 ++++++++++++------ gotham/src/handler/mod.rs | 2 +- gotham/src/middleware/session/mod.rs | 4 +- gotham/src/pipeline/chain.rs | 4 +- gotham/src/pipeline/mod.rs | 4 +- gotham/src/plain/test.rs | 4 +- gotham/src/router/route/mod.rs | 4 +- gotham/src/service/trap.rs | 16 +- gotham/src/tls/test.rs | 4 +- middleware/diesel/src/lib.rs | 4 +- 17 files changed, 200 insertions(+), 135 deletions(-) diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index a3d92033e..b659e766a 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -10,7 +10,7 @@ extern crate diesel_migrations; use diesel::prelude::*; use diesel::sqlite::SqliteConnection; use futures::prelude::*; -use gotham::handler::{HandlerError, HandlerFuture, IntoHandlerError}; +use gotham::handler::{HandlerError, HandlerFuture, MapHandlerError, MapHandlerErrorFuture}; use gotham::helpers::http::response::create_response; use gotham::hyper::{body, Body, StatusCode}; use gotham::pipeline::{new_pipeline, single::single_pipeline}; @@ -62,7 +62,7 @@ fn create_product_handler(mut state: State) -> Pin> { let rows = match query_result { Ok(rows) => rows, - Err(e) => return Err((state, e.into_handler_error())), + Err(e) => return Err((state, e.into())), }; let body = @@ -85,7 +85,7 @@ fn get_products_handler(state: State) -> Pin> { let res = create_response(&state, StatusCode::OK, mime::APPLICATION_JSON, body); Ok((state, res)) } - Err(e) => Err((state, e.into_handler_error())), + Err(e) => Err((state, e.into())), } } .boxed() @@ -103,24 +103,17 @@ fn router(repo: Repo) -> Router { }) } -fn bad_request(e: E) -> HandlerError -where - E: IntoHandlerError, -{ - e.into_handler_error().with_status(StatusCode::BAD_REQUEST) -} - async fn extract_json(state: &mut State) -> Result where T: serde::de::DeserializeOwned, { let body = body::to_bytes(Body::take_from(state)) - .map_err(bad_request) + .map_err_with_status(StatusCode::BAD_REQUEST) .await?; let b = body.to_vec(); from_utf8(&b) - .map_err(bad_request) - .and_then(|s| serde_json::from_str::(s).map_err(bad_request)) + .map_err_with_status(StatusCode::BAD_REQUEST) + .and_then(|s| serde_json::from_str::(s).map_err_with_status(StatusCode::BAD_REQUEST)) } /// Start a server and use a `Router` to dispatch requests diff --git a/examples/handlers/async_handlers/src/main.rs b/examples/handlers/async_handlers/src/main.rs index 9bb016709..358d26ab9 100644 --- a/examples/handlers/async_handlers/src/main.rs +++ b/examples/handlers/async_handlers/src/main.rs @@ -11,7 +11,7 @@ use gotham::hyper::StatusCode; #[cfg(not(test))] use gotham::hyper::{body, Client, Uri}; -use gotham::handler::{HandlerFuture, IntoHandlerError}; +use gotham::handler::{HandlerFuture}; use gotham::helpers::http::response::create_response; use gotham::router::builder::DefineSingleRoute; use gotham::router::builder::{build_simple_router, DrawRoutes}; @@ -108,7 +108,7 @@ fn series_handler(mut state: State) -> Pin> { println!("series length: {} finished", length); future::ok((state, res)) } - Err(err) => future::err((state, err.into_handler_error())), + Err(err) => future::err((state, err.into())), }) .boxed() } @@ -162,7 +162,7 @@ fn loop_handler(mut state: State) -> Pin> { println!("loop length: {} finished", length); future::ok((state, res)) } - Err(err) => future::err((state, err.into_handler_error())), + Err(err) => future::err((state, err.into())), }) .boxed() } @@ -230,7 +230,7 @@ fn parallel_handler(mut state: State) -> Pin> { println!("parallel length: {} finished", length); future::ok((state, res)) } - Err(err) => future::err((state, err.into_handler_error())), + Err(err) => future::err((state, err.into())), }) .boxed() } diff --git a/examples/handlers/form_urlencoded/src/main.rs b/examples/handlers/form_urlencoded/src/main.rs index 3e7087124..1b7b02270 100644 --- a/examples/handlers/form_urlencoded/src/main.rs +++ b/examples/handlers/form_urlencoded/src/main.rs @@ -4,7 +4,7 @@ use gotham::hyper::{body, Body, StatusCode}; use std::pin::Pin; use url::form_urlencoded; -use gotham::handler::{HandlerFuture, IntoHandlerError}; +use gotham::handler::{HandlerFuture}; use gotham::helpers::http::response::create_response; use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes}; use gotham::router::Router; @@ -25,7 +25,7 @@ fn form_handler(mut state: State) -> Pin> { let res = create_response(&state, StatusCode::OK, mime::TEXT_PLAIN, res_body); future::ok((state, res)) } - Err(e) => future::err((state, e.into_handler_error())), + Err(e) => future::err((state, e.into())), }); f.boxed() diff --git a/examples/handlers/multipart/src/main.rs b/examples/handlers/multipart/src/main.rs index b568f554f..2160095d7 100644 --- a/examples/handlers/multipart/src/main.rs +++ b/examples/handlers/multipart/src/main.rs @@ -1,6 +1,6 @@ //! An example of decoding multipart form requests use futures::prelude::*; -use gotham::handler::{HandlerFuture, IntoHandlerError}; +use gotham::handler::{HandlerFuture}; use gotham::helpers::http::response::create_response; use gotham::hyper::header::CONTENT_TYPE; use gotham::hyper::{body, Body, HeaderMap, StatusCode}; @@ -63,7 +63,7 @@ fn form_handler(mut state: State) -> Pin> { } } } - Err(e) => future::err((state, e.into_handler_error())), + Err(e) => future::err((state, e.into())), }) .boxed() } diff --git a/examples/handlers/request_data/src/main.rs b/examples/handlers/request_data/src/main.rs index 56d2c7a7b..026c52d1d 100644 --- a/examples/handlers/request_data/src/main.rs +++ b/examples/handlers/request_data/src/main.rs @@ -3,7 +3,7 @@ use futures::prelude::*; use gotham::hyper::{body, Body, HeaderMap, Method, Response, StatusCode, Uri, Version}; use std::pin::Pin; -use gotham::handler::{HandlerFuture, IntoHandlerError}; +use gotham::handler::{HandlerFuture}; use gotham::helpers::http::response::create_empty_response; use gotham::router::builder::{build_simple_router, DefineSingleRoute, DrawRoutes}; use gotham::router::Router; @@ -31,7 +31,7 @@ fn post_handler(mut state: State) -> Pin> { let res = create_empty_response(&state, StatusCode::OK); future::ok((state, res)) } - Err(e) => future::err((state, e.into_handler_error())), + Err(e) => future::err((state, e.into())), }); f.boxed() diff --git a/gotham/Cargo.toml b/gotham/Cargo.toml index f6966518e..c2e6fa075 100644 --- a/gotham/Cargo.toml +++ b/gotham/Cargo.toml @@ -33,7 +33,7 @@ bytes = "0.5" mio = "0.7" borrow-bag = { path = "../misc/borrow_bag", version = "1.0" } percent-encoding = "2.1" -pin-project = "0.4.2" +pin-project = "0.4.20" uuid = { version = "0.7", features = ["v4"] } chrono = "0.4" base64 = "0.12" diff --git a/gotham/src/handler/assets/mod.rs b/gotham/src/handler/assets/mod.rs index 4215260c2..2eed61bc2 100644 --- a/gotham/src/handler/assets/mod.rs +++ b/gotham/src/handler/assets/mod.rs @@ -22,7 +22,7 @@ use tokio::fs::File; use tokio::io::AsyncRead; use self::accepted_encoding::accepted_encodings; -use crate::handler::{Handler, HandlerFuture, IntoHandlerError, NewHandler}; +use crate::handler::{Handler, HandlerError, HandlerFuture, NewHandler}; use crate::router::response::extender::StaticResponseExtender; use crate::state::{FromState, State, StateData}; @@ -246,7 +246,8 @@ fn create_file_response(options: FileOptions, state: State) -> Pin StatusCode::FORBIDDEN, _ => StatusCode::INTERNAL_SERVER_ERROR, }; - Err((state, err.into_handler_error().with_status(status))) + let err: HandlerError = err.into(); + Err((state, err.with_status(status))) } }) .boxed() diff --git a/gotham/src/handler/error.rs b/gotham/src/handler/error.rs index 1a337256d..f842166bf 100644 --- a/gotham/src/handler/error.rs +++ b/gotham/src/handler/error.rs @@ -1,5 +1,8 @@ -use std::error::Error; -use std::fmt::{self, Debug, Display, Formatter}; +use futures::future::FusedFuture; +use std::fmt::{Debug, Display}; +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; use hyper::{Body, Response, StatusCode}; use log::{debug, trace}; @@ -10,6 +13,7 @@ use crate::state::{request_id, State}; /// Describes an error which occurred during handler execution, and allows the creation of a HTTP /// `Response`. +#[derive(Debug)] pub struct HandlerError { status_code: StatusCode, cause: anyhow::Error, @@ -17,90 +21,26 @@ pub struct HandlerError { /// Convert a generic `anyhow::Error` into a `HandlerError`, similar as you would a concrete error /// type with `into_handler_error()`. -impl From for HandlerError { - fn from(error: anyhow::Error) -> HandlerError { - trace!(" converting Error to HandlerError: {}", error); - - HandlerError { - status_code: StatusCode::INTERNAL_SERVER_ERROR, - cause: error, - } - } -} - -/// Allows conversion into a HandlerError from an implementing type. -/// -/// Futures returned from handlers can resolve to an error type with a value of `(State, -/// HandlerError)`. -/// -/// ```rust -/// # extern crate gotham; -/// # extern crate futures; -/// # -/// # use std::fs::File; -/// # use std::pin::Pin; -/// # use gotham::state::State; -/// # use gotham::handler::{IntoHandlerError, HandlerFuture}; -/// # use futures::prelude::*; -/// # -/// # #[allow(dead_code)] -/// fn my_handler(state: State) -> Pin> { -/// match File::open("config.toml") { -/// Err(e) => future::err((state, e.into_handler_error())).boxed(), -/// Ok(_) => // Create and return a response -/// # unimplemented!(), -/// } -/// } -/// # -/// # fn main() {} -pub trait IntoHandlerError { - /// Convert `self` into a `HandlerError`. - /// - /// The return value will have a `500 Internal Server Error` as the HTTP status code. See - /// `HandlerError::with_status` for an example of changing it. - fn into_handler_error(self) -> HandlerError; -} - -impl IntoHandlerError for E +impl From for HandlerError where - E: Display + Into, + E: Into + Display, { - fn into_handler_error(self) -> HandlerError { - trace!(" converting Error to HandlerError: {}", self); + fn from(error: E) -> HandlerError { + trace!(" converting Error to HandlerError: {}", error); HandlerError { status_code: StatusCode::INTERNAL_SERVER_ERROR, - cause: self.into(), + cause: error.into(), } } } -impl Display for HandlerError { - fn fmt(&self, out: &mut Formatter) -> fmt::Result { - out.write_str("handler failed to process request") - } -} - -impl Debug for HandlerError { - fn fmt(&self, out: &mut Formatter) -> fmt::Result { - Display::fmt(self, out)?; - out.write_str(" (")?; - Debug::fmt(&*self.cause, out)?; - out.write_str(")") - } -} - -impl Error for HandlerError { - fn description(&self) -> &str { - "handler failed to process request" +impl HandlerError { + /// Returns the HTTP status code associated with this `HandlerError`. + pub fn status(&self) -> StatusCode { + self.status_code } - fn cause(&self) -> Option<&dyn Error> { - Some(&*self.cause) - } -} - -impl HandlerError { /// Sets the HTTP status code of the response which is generated by the `IntoResponse` /// implementation. /// @@ -114,15 +54,14 @@ impl HandlerError { /// # use futures::prelude::*; /// # use hyper::StatusCode; /// # use gotham::state::State; - /// # use gotham::handler::{IntoHandlerError, HandlerFuture}; + /// # use gotham::handler::{HandlerError, HandlerFuture}; /// # use gotham::test::TestServer; /// # /// fn handler(state: State) -> Pin> { /// // It's OK if this is bogus, we just need something to convert into a `HandlerError`. /// let io_error = std::io::Error::last_os_error(); /// - /// let handler_error = io_error - /// .into_handler_error() + /// let handler_error = HandlerError::from(io_error) /// .with_status(StatusCode::IM_A_TEAPOT); /// /// future::err((state, handler_error)).boxed() @@ -153,12 +92,152 @@ impl IntoResponse for HandlerError { self.status_code .canonical_reason() .unwrap_or("(unregistered)",), - self.source() - .map(ToString::to_string) - .as_deref() - .unwrap_or("(none)"), + self.cause ); create_empty_response(state, self.status_code) } } + +/// This trait allows you to convert a `Result`'s `Err` case into a handler error with the given +/// status code. This is handy if you want to specify the status code but still use the `?` +/// shorthand. +/// +/// ```rust +/// # extern crate gotham; +/// # use gotham::anyhow::anyhow; +/// # use gotham::handler::{HandlerError, MapHandlerError}; +/// # use gotham::hyper::StatusCode; +/// fn handler() -> Result<(), HandlerError> { +/// let result = Err(anyhow!("just a test")); +/// result.map_err_with_status(StatusCode::IM_A_TEAPOT)?; +/// unreachable!() +/// } +/// +/// # #[allow(non_snake_case)] +/// # fn Err(err: T) -> Result<(), T> { +/// # Result::Err(err) +/// # } +/// # fn main() { +/// let response = handler(); +/// assert_eq!(response.map_err(|err| err.status()), Err(StatusCode::IM_A_TEAPOT)); +/// # } +/// ``` +pub trait MapHandlerError { + /// Equivalent of `map_err(|err| HandlerError::from(err).with_status(status_code))`. + fn map_err_with_status(self, status_code: StatusCode) -> Result; +} + +impl MapHandlerError for Result +where + E: Into + Display, +{ + fn map_err_with_status(self, status_code: StatusCode) -> Result { + self.map_err(|err| { + trace!(" converting Error to HandlerError: {}", err); + HandlerError { + status_code, + cause: err.into(), + } + }) + } +} + +// The future for `map_err_with_status`. +#[pin_project::pin_project(project = MapErrWithStatusProj, project_replace = MapErrWithStatusProjOwn)] +#[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] +pub enum MapErrWithStatus { + Incomplete { + #[pin] + future: F, + status: StatusCode, + }, + Complete, +} + +impl MapErrWithStatus { + fn new(future: F, status: StatusCode) -> Self { + Self::Incomplete { future, status } + } +} + +impl FusedFuture for MapErrWithStatus +where + F: Future>, + E: Into + Display, +{ + fn is_terminated(&self) -> bool { + matches!(self, Self::Complete) + } +} + +impl Future for MapErrWithStatus +where + F: Future>, + E: Into + Display, +{ + type Output = Result; + + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + match self.as_mut().project() { + MapErrWithStatusProj::Incomplete { future, .. } => { + let output = match future.poll(cx) { + Poll::Ready(output) => output, + Poll::Pending => return Poll::Pending, + }; + match self.project_replace(MapErrWithStatus::Complete) { + MapErrWithStatusProjOwn::Incomplete { status, .. } => { + Poll::Ready(output.map_err_with_status(status)) + } + MapErrWithStatusProjOwn::Complete => unreachable!(), + } + } + MapErrWithStatusProj::Complete => { + panic!("MapErrWithStatus must not be polled after it returned `Poll::Ready`") + } + } + } +} + +/// This trait allows you to convert a `Result`'s `Err` case into a handler error with the given +/// status code. This is handy if you want to specify the status code but still use the `?` +/// shorthand. +/// ```rust +/// # extern crate futures; +/// # extern crate gotham; +/// # use futures::executor::block_on; +/// # use gotham::anyhow::anyhow; +/// # use gotham::handler::{HandlerError, MapHandlerErrorFuture}; +/// # use gotham::hyper::StatusCode; +/// # use std::future::Future; +/// fn handler() -> impl Future> { +/// let result = async { Err(anyhow!("just a test")) }; +/// result.map_err_with_status(StatusCode::IM_A_TEAPOT) +/// } +/// +/// # #[allow(non_snake_case)] +/// # fn Err(err: T) -> Result<(), T> { +/// # Result::Err(err) +/// # } +/// # fn main() { +/// let response = block_on(handler()); +/// assert_eq!(response.map_err(|err| err.status()), Err(StatusCode::IM_A_TEAPOT)); +/// # } +/// ``` +pub trait MapHandlerErrorFuture { + /// Equivalent of `map_err(|err| HandlerError::from(err).with_status(status_code))`. + fn map_err_with_status(self, status_code: StatusCode) -> MapErrWithStatus + where + Self: Sized; +} + +impl MapHandlerErrorFuture for F +where + E: Into + Display, + F: Future>, +{ + fn map_err_with_status(self, status_code: StatusCode) -> MapErrWithStatus { + MapErrWithStatus::new(self, status_code) + } +} diff --git a/gotham/src/handler/mod.rs b/gotham/src/handler/mod.rs index b3d967a4f..27a118e2f 100644 --- a/gotham/src/handler/mod.rs +++ b/gotham/src/handler/mod.rs @@ -22,7 +22,7 @@ mod error; /// Defines handlers for serving static assets. pub mod assets; -pub use self::error::{HandlerError, IntoHandlerError}; +pub use self::error::{HandlerError, MapHandlerError, MapHandlerErrorFuture}; /// A type alias for the results returned by async fns that can be passed to to_async. pub type HandlerResult = std::result::Result<(State, Response), (State, HandlerError)>; diff --git a/gotham/src/middleware/session/mod.rs b/gotham/src/middleware/session/mod.rs index af5a59936..55580cfe7 100644 --- a/gotham/src/middleware/session/mod.rs +++ b/gotham/src/middleware/session/mod.rs @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize}; use super::cookie::CookieParser; use super::{Middleware, NewMiddleware}; -use crate::handler::{HandlerError, HandlerFuture, IntoHandlerError}; +use crate::handler::{HandlerError, HandlerFuture}; use crate::helpers::http::response::create_empty_response; use crate::state::{self, FromState, State, StateData}; @@ -1017,7 +1017,7 @@ where format!("backend failed to return session: {:?}", e), ); - future::err((state, e.into_handler_error())) + future::err((state, e.into())) } } } diff --git a/gotham/src/pipeline/chain.rs b/gotham/src/pipeline/chain.rs index 4dbb29929..fea12ebe9 100644 --- a/gotham/src/pipeline/chain.rs +++ b/gotham/src/pipeline/chain.rs @@ -7,7 +7,7 @@ use log::trace; use std::panic::RefUnwindSafe; use std::pin::Pin; -use crate::handler::{HandlerFuture, IntoHandlerError}; +use crate::handler::HandlerFuture; use crate::middleware::chain::NewMiddlewareChain; use crate::pipeline::set::PipelineSet; use crate::pipeline::Pipeline; @@ -52,7 +52,7 @@ where Ok(p) => chain.call(pipelines, state, move |state| p.call(state, f)), Err(e) => { trace!("[{}] error borrowing pipeline", request_id(&state)); - future::err((state, e.into_handler_error())).boxed() + future::err((state, e.into())).boxed() } } } diff --git a/gotham/src/pipeline/mod.rs b/gotham/src/pipeline/mod.rs index 213f71f72..71d883d1c 100644 --- a/gotham/src/pipeline/mod.rs +++ b/gotham/src/pipeline/mod.rs @@ -294,7 +294,7 @@ mod tests { use futures::prelude::*; use hyper::{Body, Response, StatusCode}; - use crate::handler::{Handler, IntoHandlerError}; + use crate::handler::Handler; use crate::middleware::Middleware; use crate::state::StateData; use crate::test::TestServer; @@ -397,7 +397,7 @@ mod tests { Ok(move |state| match pipeline.construct() { Ok(p) => p.call(state, |state| handler.handle(state)), - Err(e) => future::err((state, e.into_handler_error())).boxed(), + Err(e) => future::err((state, e.into())).boxed(), }) }) .unwrap(); diff --git a/gotham/src/plain/test.rs b/gotham/src/plain/test.rs index 5eede60ca..c798a0882 100644 --- a/gotham/src/plain/test.rs +++ b/gotham/src/plain/test.rs @@ -210,7 +210,7 @@ mod tests { use mime; use std::time::{SystemTime, UNIX_EPOCH}; - use crate::handler::{Handler, HandlerFuture, IntoHandlerError, NewHandler}; + use crate::handler::{Handler, HandlerFuture, NewHandler}; use crate::helpers::http::response::create_response; use crate::state::{client_addr, FromState, State}; use http::header::CONTENT_TYPE; @@ -357,7 +357,7 @@ mod tests { future::ok((state, res)) } - Err(e) => future::err((state, e.into_handler_error())), + Err(e) => future::err((state, e.into())), }) .boxed() } diff --git a/gotham/src/router/route/mod.rs b/gotham/src/router/route/mod.rs index 24d1e6fe9..11c59d843 100644 --- a/gotham/src/router/route/mod.rs +++ b/gotham/src/router/route/mod.rs @@ -255,7 +255,7 @@ mod tests { match route.dispatch(state).now_or_never() { Some(Ok((_state, response))) => assert_eq!(response.status(), StatusCode::ACCEPTED), - Some(Err((_state, e))) => panic!("error polling future: {}", e), + Some(Err((_state, e))) => panic!("error polling future: {:?}", e), None => panic!("expected future to be completed already"), } } @@ -287,7 +287,7 @@ mod tests { match route.dispatch(state).now_or_never() { Some(Ok((_state, response))) => assert_eq!(response.status(), StatusCode::ACCEPTED), - Some(Err((_state, e))) => panic!("error polling future: {}", e), + Some(Err((_state, e))) => panic!("error polling future: {:?}", e), None => panic!("expected future to be completed already"), } } diff --git a/gotham/src/service/trap.rs b/gotham/src/service/trap.rs index 6294213a5..b667a426c 100644 --- a/gotham/src/service/trap.rs +++ b/gotham/src/service/trap.rs @@ -1,7 +1,6 @@ //! Defines functionality for processing a request and trapping errors and panics in response //! generation. -use std::error::Error; use std::panic::catch_unwind; use std::panic::{AssertUnwindSafe, UnwindSafe}; @@ -57,11 +56,7 @@ where } fn finalize_error_response(state: State, err: HandlerError) -> Response { - error!( - "[ERROR][{}][Error: {}]", - request_id(&state), - err.source().unwrap_or(&err) - ); + error!("[ERROR][{}][Error: {:?}]", request_id(&state), err); err.into_response(&state) } @@ -84,7 +79,7 @@ mod tests { use hyper::{HeaderMap, Method, StatusCode}; - use crate::handler::{HandlerFuture, IntoHandlerError}; + use crate::handler::HandlerFuture; use crate::helpers::http::response::create_empty_response; use crate::state::set_request_id; @@ -136,11 +131,8 @@ mod tests { #[test] fn error() { - let new_handler = || { - Ok(|state| { - future::err((state, io::Error::last_os_error().into_handler_error())).boxed() - }) - }; + let new_handler = + || Ok(|state| future::err((state, io::Error::last_os_error().into())).boxed()); let mut state = State::new(); state.put(HeaderMap::new()); diff --git a/gotham/src/tls/test.rs b/gotham/src/tls/test.rs index 4ffa1b6c0..e3bad91cb 100644 --- a/gotham/src/tls/test.rs +++ b/gotham/src/tls/test.rs @@ -305,7 +305,7 @@ mod tests { use hyper::{body, Body, Response, StatusCode, Uri}; use mime; - use crate::handler::{Handler, HandlerFuture, IntoHandlerError, NewHandler}; + use crate::handler::{Handler, HandlerFuture, NewHandler}; use crate::helpers::http::response::create_response; use crate::state::{client_addr, FromState, State}; use http::header::CONTENT_TYPE; @@ -459,7 +459,7 @@ mod tests { future::ok((state, res)) } - Err(e) => future::err((state, e.into_handler_error())), + Err(e) => future::err((state, e.into())), }, ); diff --git a/middleware/diesel/src/lib.rs b/middleware/diesel/src/lib.rs index 3cdc4f9b6..717e07486 100644 --- a/middleware/diesel/src/lib.rs +++ b/middleware/diesel/src/lib.rs @@ -15,7 +15,7 @@ //! # use gotham::pipeline::*; //! # use gotham::state::{FromState, State}; //! # use gotham::helpers::http::response::create_response; -//! # use gotham::handler::{HandlerFuture, IntoHandlerError}; +//! # use gotham::handler::HandlerFuture; //! # use gotham_middleware_diesel::{self, DieselMiddleware}; //! # use diesel::{RunQueryDsl, SqliteConnection}; //! # use gotham::hyper::StatusCode; @@ -54,7 +54,7 @@ //! let res = create_response(&state, StatusCode::OK, mime::TEXT_PLAIN, body); //! Ok((state, res)) //! }, -//! Err(e) => Err((state, e.into_handler_error())), +//! Err(e) => Err((state, e.into())), //! } //! }.boxed() //! }