-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Exposing HTTP/2 and HTTP/3 protocol error codes #70684
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsExposing HTTP/2 and HTTP/3 protocol error details from
|
Author: | antonfirsov |
---|---|
Assignees: | - |
Labels: |
|
Milestone: | - |
Feels very weird to have an exception without public constructors to be honest. |
Might feel weird but not sure if it breaks any of our design guidelines. Without having use-cases to construct the exception externally, we couldn't decide how general we should go with a public constructor. Same applies for |
It does. @bartonjs can comment. |
Unit tests would benefit from a public constructor so that code like this, lightly tweaked from the motivating example, can be tested: try
{
await SomeClientMethodThatHasBeenMockedOrArrangedToThrowAProtocolException();
}
catch (HttpRequestException ex) when (ex.InnerException is ProtocolException protocolException)
{
// without a public ctor, exercising this code path in a unit test is annoying
} |
I updated the proposal with a public constructor @rzikm #70684 (comment) is also relevant for #70669 |
namespace System.Net.Http;
public sealed class HttpProtocolException : IOException
{
public HttpProtocolException(long errorCode, string message, Exception? innerException);
public long ErrorCode { get; }
} |
Exposing HTTP/2 and HTTP/3 protocol error codes from
SocketsHttpHandler
This proposal builds on our
QuicException
proposal.Background and Motivation
GRPC (and potentially other lower-level users) need a way to get the underlying HTTP/2 or HTTP/3 error codes in case a protocol error occurs.
The error code should be observable not only when an error occurs while calling an
HttpClient
method (#43239), but also when invokingStream
API-s on the response's content read stream (#62228).Proposed design
HttpProtocolException
, and embed it asHttpRequestException.InnerException
ProtocolException
directly fromHttpResponse
content read streamsEdit: Added a public constructor.
Notes
No public constructors, because we prefer to do the bare minimum to deliver a feature. This means thatWinHttpHandler
and user-madeHttpClientHandlers
won't be able to throwHttpProtocolException
for now. We can consider public constructors later, if necessary.ProtocolError
when a connection or stream is aborted, or when we detect a protocol violation ourselvesErrorCode >= 256
means HTTP/3QuicException
asProtocolException.InnerException
HttpProtocolException
for transport-level errorsAPI Usage
Over HttpClient
Over response stream
Alternative designs
Parallel independent exception types for HTTP/2 and HTTP/3
Usage
Do not define an enum, use untyped
long
error codesRisks
HttpProtocolError
enum: implementations may send unspecified error codes. If spec evolves in the future, we will have to introduce new error codes. In both cases field would contain a value outside the enum range, so users would have a workaround.HttpProtocolException
is anIOException
.The text was updated successfully, but these errors were encountered: