Commit af70a8cf authored by Andrew Imm's avatar Andrew Imm

Add 3x retries to font fetching in turbopack, similar to the webpack loader

parent 8319d6da
...@@ -742,21 +742,51 @@ async fn fetch_from_google_fonts( ...@@ -742,21 +742,51 @@ async fn fetch_from_google_fonts(
url: RcStr, url: RcStr,
virtual_path: FileSystemPath, virtual_path: FileSystemPath,
) -> Result<Option<Vc<HttpResponseBody>>> { ) -> Result<Option<Vc<HttpResponseBody>>> {
let result = fetch_client const MAX_ATTEMPTS: usize = 3;
.fetch(url, Some(rcstr!(USER_AGENT_FOR_GOOGLE_FONTS)))
.await?;
Ok(match *result { for attempt in 1..=MAX_ATTEMPTS {
Ok(r) => Some(*r.await?.body), let result = fetch_client
Err(err) => { .fetch(url.clone(), Some(rcstr!(USER_AGENT_FOR_GOOGLE_FONTS)))
err.to_issue(IssueSeverity::Warning, virtual_path) .await?;
.to_resolved()
.await?
.emit();
None match &*result {
Ok(r) => {
if attempt > 1 {
tracing::info!(
"Successfully fetched Google Font {} on attempt {}/{}",
url,
attempt,
MAX_ATTEMPTS
);
}
return Ok(Some(*r.await?.body));
}
Err(err) => {
if attempt < MAX_ATTEMPTS {
tracing::warn!(
"Failed to fetch Google Font {} (attempt {}/{}), retrying...",
url,
attempt,
MAX_ATTEMPTS
);
} else {
tracing::warn!(
"Failed to fetch Google Font {} after {} attempts",
url,
MAX_ATTEMPTS
);
err.to_issue(IssueSeverity::Warning, virtual_path)
.to_resolved()
.await?
.emit();
return Ok(None);
}
}
} }
}) }
Ok(None)
} }
async fn get_mock_stylesheet( async fn get_mock_stylesheet(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment