Skip to content

Commit a35239e

Browse files
authored
feat(mirror): do not display send request error url on oma mirror latency (#617)
1 parent 5d4c1d7 commit a35239e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/subcommand/mirror.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ fn get_latency(timeout: f64, no_progress: bool, json: bool) -> Result<i32, Outpu
499499
&client,
500500
"origin",
501501
&pb,
502+
false,
502503
)?;
503504

504505
let origin_date =
@@ -511,7 +512,7 @@ fn get_latency(timeout: f64, no_progress: bool, json: bool) -> Result<i32, Outpu
511512
.filter(|m| !["origin", "origin4", "origin6", "repo-hk", "fastly"].contains(&m.0))
512513
.map(|m| (m.0, &m.1.url))
513514
.map(|(m, url)| (m, concat_url(url, "debs/dists/stable/InRelease")))
514-
.map(|(m, url)| (m, get_mirror_date(&url, &client, m, &pb)))
515+
.map(|(m, url)| (m, get_mirror_date(&url, &client, m, &pb, true)))
515516
.filter_map(|(m, res)| {
516517
res.map_err(|e| {
517518
if let Some(pb) = &pb {
@@ -629,6 +630,7 @@ fn get_mirror_date(
629630
client: &blocking::Client,
630631
m: &str,
631632
p: &Option<OmaProgressBar>,
633+
error_without_url: bool,
632634
) -> anyhow::Result<String> {
633635
let url = Url::parse(url)?;
634636

@@ -637,7 +639,14 @@ fn get_mirror_date(
637639
.get(url)
638640
.send()
639641
.and_then(|x| x.error_for_status())
640-
.and_then(|x| x.text())?,
642+
.and_then(|x| x.text())
643+
.map_err(|e| {
644+
if error_without_url {
645+
e.without_url()
646+
} else {
647+
e
648+
}
649+
})?,
641650
"file" => std::fs::read_to_string(url.path())?,
642651
x => bail!("Unsupported protocol {x}"),
643652
};

0 commit comments

Comments
 (0)