Skip to content

Commit

Permalink
download: check for failure status codes
Browse files Browse the repository at this point in the history
Check for HTTP status codes for immediate failures in download_and_hash,
for now only 403 Forbidden and 404 Not found.
  • Loading branch information
dongsupark committed Nov 7, 2023
1 parent 13537d5 commit c3fc2b3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::error::Error;
use std::io::Write;
use std::io;

use reqwest::StatusCode;

use sha2::{Sha256, Digest};

pub struct DownloadResult<W: std::io::Write> {
Expand All @@ -19,6 +21,17 @@ where
.send()
.await?;

// Return immediately on download failure on the client side.
let status = res.status();
if status.is_client_error() {
match status {
StatusCode::FORBIDDEN | StatusCode::NOT_FOUND => {
return Err(format!("cannnot fetch remotely with status code {:?}", status).into());
}
_ => (),
}
}

let mut hasher = Sha256::new();

let mut bytes_read = 0usize;
Expand Down

0 comments on commit c3fc2b3

Please sign in to comment.