From 9a932d2d243055d022be18daf249a267218fd24a Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 20 Dec 2016 20:18:30 -0800 Subject: [PATCH] Handle bad errors before waiting for ready --- postgres-tokio/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/postgres-tokio/src/lib.rs b/postgres-tokio/src/lib.rs index d6308136..94e15a97 100644 --- a/postgres-tokio/src/lib.rs +++ b/postgres-tokio/src/lib.rs @@ -324,13 +324,11 @@ impl Connection { fn ready_err(self, body: ErrorResponseBody>) -> BoxFuture where T: 'static + Send { - self.ready(DbError::new(&mut body.fields())) - .and_then(|(e, s)| { - match e { - Ok(e) => Err(Error::Db(Box::new(e), s)), - Err(e) => Err(Error::Io(e)), - } - }) + DbError::new(&mut body.fields()) + .map_err(Error::Io) + .into_future() + .and_then(|e| self.ready(e)) + .and_then(|(e, s)| Err(Error::Db(Box::new(e), s))) .boxed() }