From 81820b0d4d488fe59b346fdaec8dbd88ae32ec30 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 25 Jun 2019 12:43:55 +0200 Subject: [PATCH] src/client/http_client.rs - download: fix error handling --- src/client/http_client.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/client/http_client.rs b/src/client/http_client.rs index 61d98ca7..d1bfea5f 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -224,16 +224,22 @@ impl HttpClient { client.request(req) .map_err(Error::from) .and_then(|resp| { - - let _status = resp.status(); // fixme: ?? - - resp.into_body() - .map_err(Error::from) - .for_each(move |chunk| { - output.write_all(&chunk)?; - Ok(()) - }) - + let status = resp.status(); + if !status.is_success() { + future::Either::A( + HttpClient::api_response(resp) + .and_then(|_| { bail!("unknown error"); }) + ) + } else { + future::Either::B( + resp.into_body() + .map_err(Error::from) + .for_each(move |chunk| { + output.write_all(&chunk)?; + Ok(()) + }) + ) + } }) }) }