Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry trigger with custom HTTP status code and Retry with delay support #4

Merged
merged 2 commits into from
Nov 28, 2021

Conversation

malcommac
Copy link
Collaborator

The following PR adds support to define custom HTTP status codes (HTTPStatusCode) which can trigger retry of a network request via the default validator object (HTTPDefaultValidator).

The class HTTPDefaultValidator now include the following property:

  • retriableHTTPStatusCodes: it defines a list of HTTPStatusCode which can trigger a retry of the call; it's a dictionaryw where the value is a TimeInterval (0 means retry immediately, a positive value like 2 means 2 seconds after retry).

In its default implementation.tooManyRequests's http status code with 3 seconds interval.
However you can create or modify the default behaviour.

This is a short example using the shared HTTPClient.shared instance:

let myValidator = HTTPDefaultValidator()
myValidator.retriableHTTPStatusCodes = [.tooManyRequests: 5] // wait 5 seconds for HTTP 429
HTTPClient.shared.validators = [myValidator]
        
request.maxRetries = 2 // you must set a retry > 1 in order to get it works
request.onRawResponse { response in
  // do something
}
request.run()

@malcommac malcommac self-assigned this Nov 28, 2021
@malcommac malcommac added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 28, 2021
@malcommac malcommac added this to the 0.9.16 milestone Nov 28, 2021
@malcommac malcommac changed the title Retry trigger with custom HTTP status code and Retry with Delay support Retry trigger with custom HTTP status code and Retry with delay support Nov 28, 2021
@malcommac malcommac merged commit 4b6dbca into 0.9.16 Nov 28, 2021
@malcommac malcommac deleted the new/3-retry-with-httpstatuscode-and-intervals branch February 18, 2022 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow request retry with custom HTTP codes (like 429 - Too Many Requests) and implement delay retry
1 participant