Skip to content

Commit

Permalink
blobs/get_blob: error on status != OK
Browse files Browse the repository at this point in the history
Before this change even error codes would be treated as success and the
body would contain the HTML formatted error message passed through to
the caller.
  • Loading branch information
steveej committed Nov 15, 2018
1 parent f854f56 commit 41695ee
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/v2/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ impl Client {
.send()
.inspect(|res| trace!("Blob GET result: {:?}", res.status()))
.and_then(|mut res| {
let body = std::mem::replace(res.body_mut(), reqwest::async::Decoder::empty());
body.concat2()
let body =
std::mem::replace(res.body_mut(), reqwest::async::Decoder::empty()).concat2();
body.join(futures::future::ok(res))
}).map_err(|e| Error::from(format!("{}", e)))
.and_then(|body| {
let mut cursor = std::io::Cursor::new(body);
let mut buf = Vec::new();
use std::io::Read;
match cursor.read_to_end(&mut buf) {
Ok(size) => {
trace!("Received {} bytes from blob", size);
Ok(buf)
.and_then(|(body, res)| {
let body_vec = body.to_vec();
let len = body_vec.len();
match res.status() {
StatusCode::OK => {
trace!("Received {} bytes from blob", len);
Ok(body_vec)
}
Err(e) => Err(Error::from(format!("{}", e))),
status => Err(Error::from(format!(
"GET request failed with status '{}' and body of size {}: {:#?}",
status, len, body_vec
))),
}
});
Box::new(fres)
Expand Down

0 comments on commit 41695ee

Please sign in to comment.