1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 22:51:07 +01:00

fix error mapping in MapErrNewService

This commit is contained in:
Nikolay Kim 2018-08-22 18:18:11 -07:00
parent c7543e7228
commit 2818540d69

View File

@ -390,7 +390,8 @@ pub struct AndThen<A, B> {
impl<A, B> AndThen<A, B> impl<A, B> AndThen<A, B>
where where
A: Service, A: Service,
B: Service<Request = A::Response, Error = A::Error>, A::Error: Into<B::Error>,
B: Service<Request = A::Response>,
{ {
/// Create new `AndThen` combinator /// Create new `AndThen` combinator
pub fn new(a: A, b: B) -> Self { pub fn new(a: A, b: B) -> Self {
@ -404,7 +405,8 @@ where
impl<A, B> Service for AndThen<A, B> impl<A, B> Service for AndThen<A, B>
where where
A: Service, A: Service,
B: Service<Request = A::Response, Error = A::Error>, A::Error: Into<B::Error>,
B: Service<Request = A::Response>,
{ {
type Request = A::Request; type Request = A::Request;
type Response = B::Response; type Response = B::Response;
@ -412,11 +414,12 @@ where
type Future = AndThenFuture<A, B>; type Future = AndThenFuture<A, B>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
let res = self.a.poll_ready(); match self.a.poll_ready() {
if let Ok(Async::Ready(_)) = res { Ok(Async::Ready(_)) => {
self.b.borrow_mut().poll_ready() self.b.borrow_mut().poll_ready()
} else { },
res Ok(Async::NotReady) => Ok(Async::NotReady),
Err(err) => Err(err.into())
} }
} }
@ -428,7 +431,8 @@ where
pub struct AndThenFuture<A, B> pub struct AndThenFuture<A, B>
where where
A: Service, A: Service,
B: Service<Request = A::Response, Error = A::Error>, A::Error: Into<B::Error>,
B: Service<Request = A::Response>,
{ {
b: Rc<RefCell<B>>, b: Rc<RefCell<B>>,
fut_b: Option<B::Future>, fut_b: Option<B::Future>,
@ -438,7 +442,8 @@ where
impl<A, B> AndThenFuture<A, B> impl<A, B> AndThenFuture<A, B>
where where
A: Service, A: Service,
B: Service<Request = A::Response, Error = A::Error>, A::Error: Into<B::Error>,
B: Service<Request = A::Response>,
{ {
fn new(fut_a: A::Future, b: Rc<RefCell<B>>) -> Self { fn new(fut_a: A::Future, b: Rc<RefCell<B>>) -> Self {
AndThenFuture { AndThenFuture {
@ -452,7 +457,8 @@ where
impl<A, B> Future for AndThenFuture<A, B> impl<A, B> Future for AndThenFuture<A, B>
where where
A: Service, A: Service,
B: Service<Request = A::Response, Error = A::Error>, A::Error: Into<B::Error>,
B: Service<Request = A::Response>,
{ {
type Item = B::Response; type Item = B::Response;
type Error = B::Error; type Error = B::Error;
@ -462,12 +468,13 @@ where
return fut.poll(); return fut.poll();
} }
match self.fut_a.poll()? { match self.fut_a.poll() {
Async::Ready(resp) => { Ok(Async::Ready(resp)) => {
self.fut_b = Some(self.b.borrow_mut().call(resp)); self.fut_b = Some(self.b.borrow_mut().call(resp));
self.poll() self.poll()
} }
Async::NotReady => Ok(Async::NotReady), Ok(Async::NotReady) => Ok(Async::NotReady),
Err(err) => Err(err.into())
} }
} }
} }
@ -496,15 +503,15 @@ impl<A, B> NewService for AndThenNewService<A, B>
where where
A: NewService< A: NewService<
Response = B::Request, Response = B::Request,
Error = B::Error,
Config = B::Config, Config = B::Config,
InitError = B::InitError, InitError = B::InitError,
>, >,
A::Error: Into<B::Error>,
B: NewService, B: NewService,
{ {
type Request = A::Request; type Request = A::Request;
type Response = B::Response; type Response = B::Response;
type Error = A::Error; type Error = B::Error;
type Service = AndThen<A::Service, B::Service>; type Service = AndThen<A::Service, B::Service>;
type Config = A::Config; type Config = A::Config;
@ -518,7 +525,8 @@ where
impl<A, B> Clone for AndThenNewService<A, B> impl<A, B> Clone for AndThenNewService<A, B>
where where
A: NewService<Response = B::Request, Error = B::Error, InitError = B::InitError> + Clone, A: NewService<Response = B::Request, InitError = B::InitError> + Clone,
A::Error: Into<B::Error>,
B: NewService + Clone, B: NewService + Clone,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
@ -557,8 +565,9 @@ where
impl<A, B> Future for AndThenNewServiceFuture<A, B> impl<A, B> Future for AndThenNewServiceFuture<A, B>
where where
A: NewService<Response = B::Request, Error = B::Error, InitError = B::InitError>, A: NewService,
B: NewService, A::Error: Into<B::Error>,
B: NewService<Request = A::Response, InitError = A::InitError>,
{ {
type Item = AndThen<A::Service, B::Service>; type Item = AndThen<A::Service, B::Service>;
type Error = B::InitError; type Error = B::InitError;
@ -608,7 +617,8 @@ where
impl<A, F, E> Service for MapErr<A, F, E> impl<A, F, E> Service for MapErr<A, F, E>
where where
A: Service, A: Service,
F: Fn(A::Error) -> E + Clone, F: Fn(A::Error) -> E,
F: Clone,
{ {
type Request = A::Request; type Request = A::Request;
type Response = A::Response; type Response = A::Response;
@ -681,7 +691,7 @@ where
impl<A, F, E> Clone for MapErrNewService<A, F, E> impl<A, F, E> Clone for MapErrNewService<A, F, E>
where where
A: NewService + Clone, A: NewService + Clone,
F: Fn(A::InitError) -> E + Clone, F: Fn(A::Error) -> E + Clone,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {