Skip to content

Commit

Permalink
Avoid failing docs check on temporary network errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Jun 27, 2024
1 parent c030748 commit d5a6b01
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Tools/GenerateRulesMissingDocumentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ await checkHelpLinkAsync(helpLinkUri).ConfigureAwait(false))
File.WriteAllText(fileWithPath, builder.ToString());
}

// NOTE: Network errors (timeouts and 5xx status codes) are not considered failures.
async Task<bool> checkHelpLinkAsync(string helpLink)
{
try
Expand All @@ -111,11 +112,28 @@ async Task<bool> checkHelpLinkAsync(string helpLink)

var request = new HttpRequestMessage(HttpMethod.Head, uri);
using var response = await httpClient.SendAsync(request).ConfigureAwait(false);
return response?.StatusCode == HttpStatusCode.OK;
var success = response?.StatusCode == HttpStatusCode.OK;

if (!success && response is not null)
{
Console.WriteLine($"##[warning]Failed to check '{helpLink}': {response.StatusCode}");
if ((int)response.StatusCode >= 500)
{
return true;
}
}

return success;
}
catch (TaskCanceledException)
{
Console.WriteLine($"##[warning]Timeout while checking '{helpLink}'.");
return true;
}
catch (WebException)
catch (HttpRequestException e)
{
return false;
Console.WriteLine($"##[warning]Failed while checking '{helpLink}' (${e.StatusCode}): ${e.Message}");
return true;
}
}

Expand Down

0 comments on commit d5a6b01

Please sign in to comment.