-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Net.Http
Milestone
Description
When the EnsureSuccessStatusCode method in the HttpResponseMessage throws a HttpRequestException exception it is not possible to determine the status code.
Add a new property named StatusCode to the HttpRequestException class which gets set by the EnsureSuccessStatusCode method of the HttpResponseMessage class.
Rationale and Usage
Allows you to determine the status code which triggered the exception.
try
{
DoSomeHttp();
}
catch (HttpRequestException e)
{
Log($"Request failed with status code: {e.StatusCode}.");
}
private void DoSomeHttp()
{
// ...
message.EnsureSuccessStatusCode();
}Proposed API
public class HttpRequestException : Exception
{
// ...
public HttpRequestException(string message, StatusCode statusCode);
public HttpRequestException(string message, Exception inner, StatusCode statusCode);
// ...
public StatusCode StatusCode { get; }
// ...
}Open Questions
Should the property have a setter?
Should the exception have a constructor that sets the property?
Should the property be nullable?
jnm2, h0useRus, Spongman, acid-chicken, justdmitry and 14 more
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Net.Http