Skip to content

Commit dc306c5

Browse files
committed
Stop retrying on 404s
1 parent 0febd98 commit dc306c5

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

  • tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils

tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/FileHelpers.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ private static string GetUrlContents(string url)
5757
using HttpClient client = new HttpClient();
5858
while (attempts <= maxRetries)
5959
{
60+
HttpResponseMessage response = null;
6061
try
6162
{
62-
HttpResponseMessage response = client.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult();
63+
response = client.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult();
6364
if (response.StatusCode == HttpStatusCode.OK)
6465
{
6566
// This writeline is probably unnecessary but good to have if there are previous attempts that failed
@@ -76,13 +77,19 @@ private static string GetUrlContents(string url)
7677
// HttpRequestException means the request failed due to an underlying issue such as network connectivity,
7778
// DNS failure, server certificate validation or timeout.
7879
Console.WriteLine($"GetUrlContents attempt number {attempts}. HttpRequestException trying to fetch {url}. Exception message = {httpReqEx.Message}");
79-
if (attempts == maxRetries)
80-
{
81-
// At this point the retries have been exhausted, let this rethrow
82-
throw;
83-
}
80+
81+
}
82+
83+
// Skip retries on a NotFound response
84+
if (response?.StatusCode == HttpStatusCode.NotFound)
85+
{
86+
return null;
87+
}
88+
89+
if (attempts < maxRetries)
90+
{
91+
System.Threading.Thread.Sleep(delayTimeInMs);
8492
}
85-
System.Threading.Thread.Sleep(delayTimeInMs);
8693
attempts++;
8794
}
8895
// This will only get hit if the final retry is non-OK status code

0 commit comments

Comments
 (0)