Skip to content

Commit a31f38a

Browse files
committed
Revert "prefetch-npm-deps: check response status..." (NixOS#365658)
2 parents c7dcafc + 59c5ef5 commit a31f38a

File tree

1 file changed

+8
-24
lines changed
  • pkgs/build-support/node/fetch-npm-deps/src

1 file changed

+8
-24
lines changed

pkgs/build-support/node/fetch-npm-deps/src/util.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use anyhow::bail;
21
use backoff::{retry, ExponentialBackoff};
32
use data_encoding::BASE64;
43
use digest::Digest;
54
use isahc::{
65
config::{CaCertificate, Configurable, RedirectPolicy, SslOption},
76
Body, Request, RequestExt,
87
};
9-
use log::info;
108
use nix_nar::{Encoder, NarError};
119
use serde_json::{Map, Value};
1210
use sha2::Sha256;
@@ -17,7 +15,7 @@ use std::{
1715
};
1816
use url::Url;
1917

20-
pub fn get_url(url: &Url) -> Result<Body, anyhow::Error> {
18+
pub fn get_url(url: &Url) -> Result<Body, isahc::Error> {
2119
let mut request = Request::get(url.as_str()).redirect_policy(RedirectPolicy::Limit(10));
2220

2321
// Respect SSL_CERT_FILE if environment variable exists
@@ -39,27 +37,16 @@ pub fn get_url(url: &Url) -> Result<Body, anyhow::Error> {
3937
if let Ok(npm_tokens) = env::var("NIX_NPM_TOKENS") {
4038
if let Ok(tokens) = serde_json::from_str::<Map<String, Value>>(&npm_tokens) {
4139
if let Some(token) = tokens.get(host).and_then(serde_json::Value::as_str) {
42-
info!("Found NPM token for {}. Adding authorization header to request.", host);
4340
request = request.header("Authorization", format!("Bearer {token}"));
4441
}
4542
}
4643
}
4744
}
4845

49-
let res = request.body(())?.send()?;
50-
if !res.status().is_success() {
51-
if res.status().is_client_error() {
52-
bail!("Client error: {}", res.status());
53-
}
54-
if res.status().is_server_error() {
55-
bail!("Server error: {}", res.status());
56-
}
57-
bail!("{}", res.status());
58-
}
59-
Ok(res.into_body())
46+
Ok(request.body(())?.send()?.into_body())
6047
}
6148

62-
pub fn get_url_body_with_retry(url: &Url) -> Result<Vec<u8>, anyhow::Error> {
49+
pub fn get_url_body_with_retry(url: &Url) -> Result<Vec<u8>, isahc::Error> {
6350
retry(ExponentialBackoff::default(), || {
6451
get_url(url)
6552
.and_then(|mut body| {
@@ -69,15 +56,12 @@ pub fn get_url_body_with_retry(url: &Url) -> Result<Vec<u8>, anyhow::Error> {
6956

7057
Ok(buf)
7158
})
72-
.map_err(|err| match err.downcast_ref::<isahc::Error>() {
73-
Some(isahc_err) => {
74-
if isahc_err.is_network() || isahc_err.is_timeout() {
75-
backoff::Error::transient(err)
76-
} else {
77-
backoff::Error::permanent(err)
78-
}
59+
.map_err(|err| {
60+
if err.is_network() || err.is_timeout() {
61+
backoff::Error::transient(err)
62+
} else {
63+
backoff::Error::permanent(err)
7964
}
80-
None => backoff::Error::permanent(err),
8165
})
8266
})
8367
.map_err(|backoff_err| match backoff_err {

0 commit comments

Comments
 (0)