|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | | - |
6 | 5 | using System.Diagnostics.Contracts; |
7 | 6 | using System.IO; |
8 | 7 | using System.Net; |
9 | 8 | using System.Net.Http; |
10 | 9 | using System.Net.Security; |
| 10 | +using System.Net.Sockets; |
11 | 11 | using System.Runtime; |
12 | 12 | using System.Runtime.CompilerServices; |
| 13 | +using System.Security.Authentication; |
13 | 14 | using System.Security.Principal; |
14 | 15 | using System.ServiceModel.Security; |
15 | 16 | using System.ServiceModel.Security.Tokens; |
@@ -132,6 +133,24 @@ public static Exception ConvertHttpRequestException(HttpRequestException excepti |
132 | 133 | Contract.Assert(exception.InnerException != null, "InnerException must be set to be able to convert"); |
133 | 134 |
|
134 | 135 | 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 | + |
135 | 154 | switch (hresult) |
136 | 155 | { |
137 | 156 | // .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