Skip to content

Commit

Permalink
Avoid duplicated message in WebException (dotnet/corefx#42195)
Browse files Browse the repository at this point in the history
In a bunch of places, including in HttpClient, when a new exception instance is created to wrap an inner exception, the inner exception's message is then used as the message for the wrapping exception.  WebRequest.CreateCompatibleException is taking such an HttpRequestException and concatenating the outer and inner exception's messages, which means it's often duplicating the exact same message twice.

Since we're including the exception as the inner exception, there's no need for such duplication... we can just follow suit and use the outer exception's message without concatenation.

Commit migrated from dotnet/corefx@d7fbeca
  • Loading branch information
stephentoub authored Oct 29, 2019
1 parent 5a7ed95 commit a2feba5
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/libraries/System.Net.Requests/src/System/Net/WebException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,12 @@ public override void GetObjectData(SerializationInfo serializationInfo, Streamin
internal static Exception CreateCompatibleException(Exception exception)
{
Debug.Assert(exception != null);
if (exception is HttpRequestException)
if (exception is HttpRequestException hre)
{
Exception inner = exception.InnerException;
string message = inner != null ?
exception.Message + " " + inner.Message :
exception.Message;

return new WebException(
message,
exception.Message,
exception,
GetStatusFromException(exception as HttpRequestException),
GetStatusFromException(hre),
null);
}
else if (exception is TaskCanceledException)
Expand Down

0 comments on commit a2feba5

Please sign in to comment.