Skip to content

Surface HttpRequestException from AndroidMessageHandler#11682

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-httpclient-webexception-issue
Draft

Surface HttpRequestException from AndroidMessageHandler#11682
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-httpclient-webexception-issue

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Xamarin.Android.Net.AndroidMessageHandler reported transport/protocol failures as the legacy System.Net.WebException, contradicting the documented HttpClient.SendAsync contract (which throws HttpRequestException).

Changes

  • AndroidMessageHandler: all WebException throw sites in the request path (timeout, protocol, security, IO, connect, max‑redirections, invalid redirect URI, protocol‑method setup) now throw HttpRequestException.
  • Back-compat: the original WebException — including its WebExceptionStatus — is kept as the InnerException, so code migrated from classic Xamarin.Android that inspects status (and existing test helpers that walk the inner chain) keeps working. Centralized in one helper:
static HttpRequestException CreateHttpRequestException (string message, Exception? innerException, WebExceptionStatus status)
    => new HttpRequestException (message, new WebException (message, innerException, status, null));
  • Tests: connecting to an unused port asserts HttpRequestException; exceeding MaxAutomaticRedirections asserts HttpRequestException with the preserved inner WebException.

Notes

  • Public API surface is unchanged; only the thrown exception type differs.
  • Callers catching WebException at the top level will no longer match — this is the intended behavioral change. The WebException remains reachable via ex.InnerException.

Copilot AI and others added 2 commits June 17, 2026 14:22
…andler

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix HttpClient throwing WebException instead of HttpRequestException Surface HttpRequestException from AndroidMessageHandler Jun 17, 2026
Copilot AI requested a review from jonathanpeppers June 17, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants