Skip to content

Commit 5dc61c0

Browse files
mconnewStephenBonikowsky
authored andcommitted
Add new exception handling logic for SocketsHttpHandler differences
1 parent 93a86bc commit 5dc61c0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/System.Private.ServiceModel/src/System.Private.ServiceModel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@
104104
</Content>
105105
</ItemGroup>
106106
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
107-
</Project>
107+
</Project>

src/System.Private.ServiceModel/src/System/ServiceModel/Channels/HttpChannelHelpers.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
65
using System.Diagnostics.Contracts;
76
using System.IO;
87
using System.Net;
98
using System.Net.Http;
109
using System.Net.Security;
10+
using System.Net.Sockets;
1111
using System.Runtime;
1212
using System.Runtime.CompilerServices;
13+
using System.Security.Authentication;
1314
using System.Security.Principal;
1415
using System.ServiceModel.Security;
1516
using System.ServiceModel.Security.Tokens;
@@ -132,6 +133,24 @@ public static Exception ConvertHttpRequestException(HttpRequestException excepti
132133
Contract.Assert(exception.InnerException != null, "InnerException must be set to be able to convert");
133134

134135
uint hresult = (uint)exception.InnerException.HResult;
136+
var innerSocketException = exception.InnerException as SocketException;
137+
if (innerSocketException != null)
138+
{
139+
var socketErrorCode = innerSocketException.SocketErrorCode;
140+
switch (socketErrorCode)
141+
{
142+
case SocketError.HostNotFound:
143+
return new EndpointNotFoundException(SR.Format(SR.EndpointNotFound, request.RequestUri.AbsoluteUri), exception);
144+
default:
145+
break;
146+
}
147+
}
148+
149+
if (exception.InnerException is AuthenticationException)
150+
{
151+
return new SecurityNegotiationException(SR.Format(SR.TrustFailure, request.RequestUri.Authority), exception);
152+
}
153+
135154
switch (hresult)
136155
{
137156
// .Net Native HttpClientHandler sometimes reports an incorrect handle state when a connection is aborted, so we treat it as a connection reset error

0 commit comments

Comments
 (0)