Skip to content

Commit 4ae6432

Browse files
committed
Fix not erroring out on a bad HTTP status code
1 parent d4775d2 commit 4ae6432

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/lock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use walkdir::WalkDir;
2424
use crate::{
2525
config::{Config, ExternalPlugin, GitReference, InlinePlugin, Plugin, Source, Template},
2626
context::{LockContext as Context, Settings, SettingsExt},
27-
util::{git, TempPath},
27+
util::{self, git, TempPath},
2828
};
2929

3030
/// The maximmum number of threads to use while downloading sources.
@@ -209,7 +209,7 @@ impl Source {
209209
}
210210

211211
let mut response =
212-
reqwest::blocking::get(url.clone()).with_context(s!("failed to download `{}`", url))?;
212+
util::download(url.clone()).with_context(s!("failed to download `{}`", url))?;
213213
fs::create_dir_all(&dir).with_context(s!("failed to create dir `{}`", dir.display()))?;
214214
let mut temp_file = TempPath::new(&file);
215215
temp_file.write(&mut response).with_context(s!(

src/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99

1010
use anyhow::{Context as ResultExt, Error, Result};
1111
use fs2::{lock_contended_error, FileExt};
12+
use url::Url;
1213

1314
use crate::context::{Context, SettingsExt};
1415

@@ -31,6 +32,11 @@ fn nuke_path(path: &Path) -> io::Result<()> {
3132
}
3233
}
3334

35+
/// Download a remote file and handle status code errors.
36+
pub fn download(url: Url) -> reqwest::Result<reqwest::blocking::Response> {
37+
Ok(reqwest::blocking::get(url)?.error_for_status()?)
38+
}
39+
3440
/////////////////////////////////////////////////////////////////////////
3541
// PathExt trait
3642
/////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)