Example #1
0
        private static HttpResponseMessage BuildTimedoutResponse(HttpRequestMessage request, TimeSpan timeout)
        {
            HttpRequestLog.Error($"Http request timedout after {timeout.TotalMilliseconds}ms | url: {request.RequestUri} | method:{request.Method}");

            var rsp = new HttpResponseMessage
            {
                StatusCode   = System.Net.HttpStatusCode.RequestTimeout,
                ReasonPhrase = "HttpClientTimedout"
            };

            rsp.Headers.Add(Bolt.FluentHttpClient.Abstracts.Constants.HeaderNameError, "HttpClient raised timeoutexception");

            return(rsp);
        }
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var retryCount = request.GetPropertyValueOrDefault <int?>(Bolt.FluentHttpClient.Abstracts.Constants.PropertyNameRetryCount) ?? 0;

            HttpResponseMessage response = null;

            for (var i = 0; i < retryCount + 1; i++)
            {
                response = await base.SendAsync(request, cancellationToken);

                if (!ShouldRetry(response))
                {
                    return(response);
                }
                else
                {
                    HttpRequestLog.Error($"Retrying {i+1} time(s) after http request failed with statuscode {response.StatusCode} | url: {request.RequestUri} | method:{request.Method}");
                }
            }

            return(response);
        }