title: How to set Polly Retry for the set specific StatusCodes only
body: <p>I have a couple of questions around similar concern:
  I'm making a call to EmailServer and using Polly Policy to WaitAndRetry. But I would like the Retry to happen only for specific timeouts: 5xx and 429 (and ignore the rest of the 4xx).</p>
  
  <p>How to make it more elegant and also cover all of the 5xx possibility (as the HttpStatusCode below does not cover all of the 5xx and also does not cover 429)?</p>
  
  <p>Currently I have my code as following (2 parts/options):</p>
  
  <pre><code>private readonly HttpStatusCode[] _retryHttpStatusCodesList =
      new[]
      {
          HttpStatusCode.InternalServerError,
          HttpStatusCode.NotImplemented,            
          HttpStatusCode.BadGateway,
          HttpStatusCode.ServiceUnavailable,
          HttpStatusCode.GatewayTimeout,
          HttpStatusCode.HttpVersionNotSupported,
          HttpStatusCode.RequestTimeout,
          HttpStatusCode.Unauthorized,
          HttpStatusCode.RequestEntityTooLarge
      };
  </code></pre>
  
  <p>OPTION 1:    </p>
  
  <pre><code>   var waitAndRetryPolicy = Policy.Handle&lt;Exception&gt;()
                  .OrResult&lt;HttpResponseMessage&gt;(r =&gt;  _retryHttpStatusCodesList.Contains(r.StatusCode))
                  .RetryAsync(2, (ex, retryCount) =&gt; { Console.WriteLine($"Retry count {retryCount}"); });
  </code></pre>
  
  <p>OPTION 2 (this one I cannot figure out how to put the check for StatusCode at all):</p>
  
  <pre><code>var waitAndRetryPolicy = Policy.Handle&lt;Exception&gt;()
              .WaitAndRetryAsync(_maxRetries, retryAttempt =&gt; TimeSpan.FromMinutes(Math.Pow(_waitMinutes, retryAttempt)), 
              (ex, timeSpan) =&gt; 
              { 
                  Console.WriteLine($"Log Error {ex}"); 
              });
  
     SendGridClient client = new SendGridClient ();
     var response = await policy.ExecuteAsync (() =&gt; 
                 client.SendEmailAsync(new SendGridMessage));
  </code></pre>