Search code examples
.netpolly

What HTTP error codes are retried by Polly (.Net) by default?


I know I can specify the list of HTTP error codes (e.g. 408, 502, 503, etc. ) I would like to get retried using Polly, but what is the list of these codes that would be retried by default if none is specified?


Solution

  • What is the list of [Http status] codes that would be retried by default [by Polly] if none is specified?

    Polly on its own contains no built-in definitions of what it retries, you as the user specify that when defining a policy.

    Polly with HttpClientFactory (using services.AddHttpClient(...).AddTransientHttpErrorPolicy(...) in StartUp in .Net Core) retries the following items, per the Polly with HttpClientFactory documentation:

    • Network failures (System.Net.Http.HttpRequestException)
    • HTTP 5XX status codes (server errors)
    • HTTP 408 status code (request timeout)

    This should also be shown in the intellisense when you hover over the method.

    The HandleTransientHttpError() method available via the Polly.Extensions.Http package also handles the same set of exceptions and status codes.