Skip to content

Wrap connection exceptions in HttpRequestException #7661

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

Merged
merged 5 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
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 @@ -494,7 +494,11 @@ Task ConnectAsync (HttpURLConnection httpConnection, CancellationToken ct)
Logger.Log (LogLevel.Info, LOG_APP, $"Exception caught while cancelling connection: {ex}");
ct.ThrowIfCancellationRequested ();
}
throw;

// All exceptions related to connectivity should be wrapped in HttpRequestException. In theory it is possible that the exception will be
// thrown for another reason above, but it's OK to wrap it in HttpRequestException anyway, since we're working in the context of
// `ConnectAsync` which, from the end user's point of view, is 100% related to connectivity.
throw new HttpRequestException ("Connection failure", ex);
}
}, ct);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ private async Task AssertRejectsRemoteCertificate (Func<Task> makeRequest)
Assert.Fail ("The request wasn't rejected");
}
#if NET
catch (System.Net.WebException ex) {}
// While technically we should be throwing only HttpRequestException (as per HttpClient.SendAsync docs), in reality
// we need to consider legacy code that migrated to .NET and may still expect WebException. Thus, we throw both
// of these and we need to catch both here
catch (System.Net.WebException) {}
#else
catch (Java.IO.IOException) {}
#endif
catch (System.Net.Http.HttpRequestException) {}
}
}
}