/// <summary> /// Gets the exception. /// </summary> /// <param name="ex">The ex.</param> /// <param name="options">The options.</param> /// <returns>HttpException.</returns> private HttpException GetException(WebException ex, HttpRequestOptions options) { _logger.ErrorException("Error getting response from " + options.Url, ex); var exception = new HttpException(ex.Message, ex); var response = ex.Response as HttpWebResponse; if (response != null) { exception.StatusCode = response.StatusCode; } return exception; }
private Exception GetException(Exception ex, HttpRequestOptions options, HttpClientInfo client) { if (ex is HttpException) { return ex; } var webException = ex as WebException ?? ex.InnerException as WebException; if (webException != null) { if (options.LogErrors) { _logger.ErrorException("Error getting response from " + options.Url, ex); } var exception = new HttpException(ex.Message, ex); var response = webException.Response as HttpWebResponse; if (response != null) { exception.StatusCode = response.StatusCode; if ((int)response.StatusCode == 429) { client.LastTimeout = DateTime.UtcNow; } } return exception; } var operationCanceledException = ex as OperationCanceledException ?? ex.InnerException as OperationCanceledException; if (operationCanceledException != null) { return GetCancellationException(options, client, options.CancellationToken, operationCanceledException); } if (options.LogErrors) { _logger.ErrorException("Error getting response from " + options.Url, ex); } return ex; }
private Exception GetExceptionToThrow(Exception ex, HttpRequest options, DateTime requestTime) { var webException = ex as WebException ?? ex.InnerException as WebException; if (webException != null) { Logger.ErrorException("Error getting response from " + options.Url, ex); var httpException = new HttpException(ex.Message, ex); var response = webException.Response as HttpWebResponse; if (response != null) { httpException.StatusCode = response.StatusCode; OnResponseReceived(options.Url, options.Method, response.StatusCode, ConvertHeaders(response), requestTime); } return httpException; } var timeoutException = ex as TimeoutException ?? ex.InnerException as TimeoutException; if (timeoutException != null) { Logger.ErrorException("Request timeout to " + options.Url, ex); var httpException = new HttpException(ex.Message, ex) { IsTimedOut = true }; return httpException; } Logger.ErrorException("Error getting response from " + options.Url, ex); return ex; }