Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechBiezynski committed Oct 9, 2024
1 parent c3937dc commit dd57459
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/image_provider/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod client {
use std::time::Duration;

use async_trait::async_trait;
use futures::StreamExt;
use futures::{TryStreamExt};
use log::error;
use reqwest::{Client, Url};

Expand Down Expand Up @@ -87,14 +87,13 @@ pub mod client {
let mut stream = response.bytes_stream();
let mut total_bytes = 0;
let mut bytes = Vec::new();
while let Some(chunk) = stream.next().await {
let chunk = chunk.map_err(|e| {
error!(
"failed to read the binary payload of the image '{}'. error: {}",
resource, e
);
ImageDownloadFailed
})?;
while let Some(chunk) = stream.try_next().await.map_err(|e| {
error!(
"failed to read the binary payload of the image '{}'. error: {}",
resource, e
);
ImageDownloadFailed
})? {
total_bytes += chunk.len() as u32;
if total_bytes > max_size {
error!(
Expand Down

0 comments on commit dd57459

Please sign in to comment.