Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Nov 24, 2023
1 parent 33f9d6b commit 1b098a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

using Ocelot.Configuration;
using Ocelot.DependencyInjection;
using Ocelot.Errors;
using Ocelot.Logging;
using Ocelot.Provider.Polly.Interfaces;
using Ocelot.Requester;

using Polly.CircuitBreaker;
using Polly.Timeout;

Expand All @@ -17,7 +15,8 @@ public static class OcelotBuilderExtensions
{
public static IOcelotBuilder AddPolly<T>(this IOcelotBuilder builder,
QosDelegatingHandlerDelegate delegatingHandler,
Dictionary<Type, Func<Exception, Error>> errorMapping) where T : class, IPollyQoSProvider<HttpResponseMessage>
Dictionary<Type, Func<Exception, Error>> errorMapping)
where T : class, IPollyQoSProvider<HttpResponseMessage>
{
builder.Services
.AddSingleton(errorMapping)
Expand Down
17 changes: 8 additions & 9 deletions src/Ocelot.Provider.Polly/PollyPoliciesDelegatingHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

using Ocelot.Configuration;
using Ocelot.Logging;
using Ocelot.Provider.Polly.Interfaces;

using Polly.CircuitBreaker;

using System.Diagnostics;

namespace Ocelot.Provider.Polly;
Expand Down Expand Up @@ -36,18 +33,20 @@ private IPollyQoSProvider<HttpResponseMessage> GetQoSProvider()
/// <summary>
/// Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
/// </summary>
/// <param name="request">Downstream request</param>
/// <param name="cancellationToken"></param>
/// <exception cref="BrokenCircuitException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <returns></returns>
/// <param name="request">Downstream request.</param>
/// <param name="cancellationToken">Token to cancel the task.</param>
/// <returns>A <see cref="Task{HttpResponseMessage}"/> object of a <see cref="HttpResponseMessage"/> result.</returns>
/// <exception cref="BrokenCircuitException">Exception thrown when a circuit is broken.</exception>
/// <exception cref="HttpRequestException">Exception thrown by <see cref="HttpClient"/> and <see cref="HttpMessageHandler"/> classes.</exception>
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var qoSProvider = GetQoSProvider();
// at least one policy (timeout) will be returned

// At least one policy (timeout) will be returned
// AsyncPollyPolicy can't be null
// AsyncPollyPolicy constructor will throw if no policy is provided
var policy = qoSProvider.GetPollyPolicyWrapper(_route).AsyncPollyPolicy;

return await policy.ExecuteAsync(async () => await base.SendAsync(request, cancellationToken));
}
}

0 comments on commit 1b098a4

Please sign in to comment.