diff options
author | Antoine Büsch <antoine.busch@gmail.com> | 2018-09-24 17:06:01 +1000 |
---|---|---|
committer | Antoine Büsch <antoine.busch@gmail.com> | 2018-09-24 17:06:01 +1000 |
commit | e4f9e01ba8762996eeee3d58bfce203ceebc8ef7 (patch) | |
tree | f332c979f207d97f20a4e2e13e135179dc2edb42 /src/transport.rs | |
parent | 8d6e87c82ca8cbb1942a9cc60d85bab8ed678195 (diff) |
Remove use of wait() in get_error_message()
Diffstat (limited to 'src/transport.rs')
-rw-r--r-- | src/transport.rs | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/src/transport.rs b/src/transport.rs index 7c80af3..e3c4604 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -8,7 +8,7 @@ use hyper::client::{Client, HttpConnector}; use hyper::{Method, Request, Response, StatusCode}; use hyper::header; use hyper_openssl::HttpsConnector; -use hyper::rt::{Future, Stream}; +use hyper::rt::Stream; use hyperlocal::Uri as DomainUri; use hyperlocal::UnixConnector; use mime::Mime; @@ -132,7 +132,7 @@ impl Transport { StatusCode::BAD_REQUEST => { Err(Error::Fault { code: res.status(), - message: get_error_message(res).unwrap_or( + message: self.get_error_message(res).unwrap_or( "bad parameter" .to_owned(), ), @@ -141,7 +141,7 @@ impl Transport { StatusCode::NOT_FOUND => { Err(Error::Fault { code: res.status(), - message: get_error_message(res).unwrap_or( + message: self.get_error_message(res).unwrap_or( "not found".to_owned(), ), }) @@ -149,7 +149,7 @@ impl Transport { StatusCode::NOT_MODIFIED => { Err(Error::Fault { code: res.status(), - message: get_error_message(res).unwrap_or( + message: self.get_error_message(res).unwrap_or( "not modified" .to_owned(), ), @@ -158,7 +158,7 @@ impl Transport { StatusCode::NOT_ACCEPTABLE => { Err(Error::Fault { code: res.status(), - message: get_error_message(res).unwrap_or( + message: self.get_error_message(res).unwrap_or( "not acceptable" .to_owned(), ), @@ -167,7 +167,7 @@ impl Transport { StatusCode::CONFLICT => { Err(Error::Fault { code: res.status(), - message: get_error_message(res).unwrap_or( + message: self.get_error_message(res).unwrap_or( "conflict found" .to_owned(), ), @@ -176,7 +176,7 @@ impl Transport { StatusCode::INTERNAL_SERVER_ERROR => { Err(Error::Fault { code: res.status(), - message: get_error_message(res).unwrap_or( + message: self.get_error_message(res).unwrap_or( "internal server error" .to_owned(), ), @@ -203,30 +203,31 @@ impl Transport { Transport::Unix { ref runtime, .. } => runtime.borrow_mut(), } } -} -/// Extract the error message content from an HTTP response that -/// contains a Docker JSON error structure. -fn get_error_message(res: Response<Body>) -> Option<String> { - let chunk = match res.into_body().concat2().wait() { - Ok(c) => c, - Err(..) => return None, - }; - - match String::from_utf8(chunk.into_iter().collect()) { - Ok(output) => { - let json_response = json::Json::from_str(output.as_str()).ok(); - let message = json_response - .as_ref() - .and_then(|x| x.as_object()) - .and_then(|x| x.get("message")) - .and_then(|x| x.as_string()) - .map(|x| x.to_owned()); - - message + /// Extract the error message content from an HTTP response that + /// contains a Docker JSON error structure. + fn get_error_message(&self, res: Response<Body>) -> Option<String> { + let chunk = match self.runtime().block_on(res.into_body().concat2()) { + Ok(c) => c, + Err(..) => return None, + }; + + match String::from_utf8(chunk.into_iter().collect()) { + Ok(output) => { + let json_response = json::Json::from_str(output.as_str()).ok(); + let message = json_response + .as_ref() + .and_then(|x| x.as_object()) + .and_then(|x| x.get("message")) + .and_then(|x| x.as_string()) + .map(|x| x.to_owned()); + + message + } + Err(..) => { + None + }, } - Err(..) => { - None - }, } } + |