From c3fc2b328f6789d69297d86b97ae4fa0b4adf212 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Tue, 7 Nov 2023 17:55:57 +0100 Subject: [PATCH] download: check for failure status codes Check for HTTP status codes for immediate failures in download_and_hash, for now only 403 Forbidden and 404 Not found. --- src/download.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/download.rs b/src/download.rs index 56ecb33..2d9c163 100644 --- a/src/download.rs +++ b/src/download.rs @@ -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 { @@ -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;