Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTTP] Catch and ignore exception from an external server #89452

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -1289,7 +1290,22 @@ public async Task GetAsync_SetAutomaticDecompression_ContentDecompressed_Deflate
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (HttpClient client = CreateHttpClient(handler))
{
Assert.Contains(expectedContent, await client.GetStringAsync(uri));
try
{
using HttpResponseMessage response = await client.GetAsync(uri);
if (response.StatusCode is HttpStatusCode.GatewayTimeout or HttpStatusCode.BadGateway)
{
// Ignore the erroneous status code, the test depends on an external server that is out of our control.
_output.WriteLine(response.ToString());
return;
}
Assert.Contains(expectedContent, await response.Content.ReadAsStringAsync());
}
catch (HttpRequestException hre) when (hre.InnerException is SocketException se && (se.SocketErrorCode is SocketError.WouldBlock or SocketError.TryAgain))
{
// Ignore the exception, the test depends on an external server that is out of our control.
_output.WriteLine(hre.ToString());
}
}
}

Expand Down
Loading