public static int ConvertErrorCodeToHR(int error)
{
// This method allows common error detection code to be used by consumers
// of HttpClient. This method converts the ErrorCode returned by WinHTTP
// to the same HRESULT value as is provided in the .Net Native implementation
// of HttpClient under the same error conditions. Clients would access
// HttpRequestException.InnerException.HRESULT to discover what caused
// the exception.
switch ((uint)error)
{
case Interop.WinHttp.ERROR_WINHTTP_CONNECTION_ERROR:
return(unchecked ((int)Interop.WinHttp.WININET_E_CONNECTION_RESET));
default:
// Marshal.GetHRForLastWin32Error can't be used as not all error codes originate from native
// code.
return(Interop.HRESULT_FROM_WIN32(error));
}
}