First, the AddTransientHttpErrorPolicy has been preconfigured errors to handle errors in the following categories: Network failures, http 5XX and Http 408 status code.

And since this Policy was configured to the CustomClientFactory, only the http request which is sent from the CustomClientFactory will use this policy, it means that if you directly using Postman to access the external service, without via the CustomClientFactory, it will not trigger this policy.
You can refer the following sample:
Prerequisites: Install the Microsoft.Extensions.Http.Polly package
Create a WeatherForecastController controller: In this controller, since there have two get method with the same route, it will show the 500 error.
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
[HttpGet]
public IEnumerable<string> Get(int id)
{
return new string[] { "value1", "value2" };
}
}
Then Create a TestClientFactory with the following code:
public class TestClientFactory
{
private readonly HttpClient _httpClient;
public TestClientFactory(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<List<WeatherForecast>> GetWeather()
{
_httpClient.BaseAddress = new Uri("https://localhost:5001");
return await _httpClient.GetFromJsonAsync<List<WeatherForecast>>("WeatherForecast");
}
}
And configure the retry policy in the ConfigureService method:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddHttpClient<TestClientFactory>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5))
.AddTransientHttpErrorPolicy(
p => p.WaitAndRetryAsync(3,
retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt) * 1)));
//you can also use the following method.
//.AddPolicyHandler(GetRetryPolicy());
}
//private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
//{
// return HttpPolicyExtensions
// .HandleTransientHttpError()
// .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(10));
//}
Then, create a Test API controller to use the TestClientFactory:
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
private readonly TestClientFactory _testClient;
public TestController(TestClientFactory testClient)
{
_testClient = testClient;
}
[HttpGet]
[Route("weather")]
public async Task<IActionResult> GetWeatherAsync()
{
return Ok(await _testClient.GetWeather());
}
}
After running the application, we can see that:
When using the postman directly access the WeatherForecastController, the result as below:

When using the postman access the WeatherForecastController via the CustomClientFactory, the result like this:

We can see that the retry policy works and it try multiple times.
HttpRequestExceptionor the status code is either 408 or 5xx. Are you sure that one of these conditions are met?