Skip to content

Commit

Permalink
Fix not erroring out on a bad HTTP status code
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Jun 4, 2020
1 parent d4775d2 commit 4ae6432
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use walkdir::WalkDir;
use crate::{
config::{Config, ExternalPlugin, GitReference, InlinePlugin, Plugin, Source, Template},
context::{LockContext as Context, Settings, SettingsExt},
util::{git, TempPath},
util::{self, git, TempPath},
};

/// The maximmum number of threads to use while downloading sources.
Expand Down Expand Up @@ -209,7 +209,7 @@ impl Source {
}

let mut response =
reqwest::blocking::get(url.clone()).with_context(s!("failed to download `{}`", url))?;
util::download(url.clone()).with_context(s!("failed to download `{}`", url))?;
fs::create_dir_all(&dir).with_context(s!("failed to create dir `{}`", dir.display()))?;
let mut temp_file = TempPath::new(&file);
temp_file.write(&mut response).with_context(s!(
Expand Down
6 changes: 6 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{

use anyhow::{Context as ResultExt, Error, Result};
use fs2::{lock_contended_error, FileExt};
use url::Url;

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

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

/// Download a remote file and handle status code errors.
pub fn download(url: Url) -> reqwest::Result<reqwest::blocking::Response> {
Ok(reqwest::blocking::get(url)?.error_for_status()?)
}

/////////////////////////////////////////////////////////////////////////
// PathExt trait
/////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4ae6432

Please sign in to comment.