1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-09 16:10:42 +00:00

replace some std::error::Error bounds with Into<HandlerError>

This commit is contained in:
Dominic 2021-02-03 22:58:08 +01:00
parent 9e65540cd8
commit 8b73701405
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
7 changed files with 21 additions and 16 deletions

View file

@ -8,6 +8,8 @@ use crate::{
Endpoint, FromBody, Resource, Response
};
#[cfg(feature = "cors")]
use gotham::router::route::matcher::AccessControlRequestMethodMatcher;
use gotham::{
handler::HandlerError,
helpers::http::response::{create_empty_response, create_response},
@ -16,9 +18,7 @@ use gotham::{
router::{
builder::{DefineSingleRoute, DrawRoutes, RouterBuilder, ScopeBuilder},
non_match::RouteNonMatch,
route::matcher::{
AcceptHeaderRouteMatcher, AccessControlRequestMethodMatcher, ContentTypeHeaderRouteMatcher, RouteMatcher
}
route::matcher::{AcceptHeaderRouteMatcher, ContentTypeHeaderRouteMatcher, RouteMatcher}
},
state::{FromState, State}
};
@ -87,7 +87,11 @@ fn response_from(res: Response, state: &State) -> gotham::hyper::Response<Body>
r
}
async fn endpoint_handler<E: Endpoint>(state: &mut State) -> Result<gotham::hyper::Response<Body>, HandlerError> {
async fn endpoint_handler<E: Endpoint>(state: &mut State) -> Result<gotham::hyper::Response<Body>, HandlerError>
where
E: Endpoint,
<E::Output as ResourceResult>::Err: Into<HandlerError>
{
trace!("entering endpoint_handler");
let placeholders = E::Placeholders::take_from(state);
let params = E::Params::take_from(state);
@ -120,7 +124,7 @@ async fn endpoint_handler<E: Endpoint>(state: &mut State) -> Result<gotham::hype
};
let out = E::handle(state, placeholders, params, body).await;
let res = out.into_response().await?;
let res = out.into_response().await.map_err(Into::into)?;
debug!("Returning response {:?}", res);
Ok(response_from(res, state))
}