Preserve HTTP status codes across target frameworks (#1767)

Copilot-Session: 9a49da98-c8d8-4b90-a6ed-50afe18ac981
This commit is contained in:
Pranav Senthilnathan 2026-07-29 12:35:12 -07:00 • committed by GitHub
commit 5c305450cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -146,14 +146,10 @@ internal sealed partial class AutoDetectingClientSessionTransport : ITransport
// keep HttpRequestException as the surfaced type so existing callers can still catch it and read StatusCode.
await sseTransport.DisposeAsync().ConfigureAwait(false);
LogSseFallbackFailedAfterStreamableHttp(_name, sseError);
#if NET
throw new HttpRequestException(streamableHttpError.Message, sseError, streamableHttpError.StatusCode);
#else
// net472 has no HttpRequestException overload that carries a status code, so this target
// preserves the status text in the message but not a programmatic StatusCode. Preserving the
// status code is intentionally net5+ only rather than an oversight.
throw new HttpRequestException(streamableHttpError.Message, sseError);
#endif
throw HttpRequestExceptionExtensions.Create(
streamableHttpError.Message,
sseError,
streamableHttpError.GetStatusCode());
}
catch
{