-
Notifications
You must be signed in to change notification settings - Fork 980
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
Unable to use Retry Adaptor and POST requests #1272
Comments
Hi @doutatsu, the retry middleware is not at fault here, it's the fact that your POST request is trying to send a body. Now, this is where Faraday middleware comes to the rescue and make your life easier! connection =
Faraday.new(url: 'www.google.com', request: { timeout: 3, open_timeout: 1 }) do |f|
f.request :url_encoded
f.request :retry, {
max: 4,
interval: 0.05,
interval_randomness: 0.5,
backoff_factor: 2,
retry_statuses: [429, 408]
}
end And the Please do let me know if the above helps! |
@iMacTia Thanks for the detailed response, I am aware of that, but what is the reason for it just working out of the box, when I don't add additional adapters (retry in my case). Was there some default adapters already added? Looking at the connection without a block, I can see that the POST request does generate correct headers: Which means, when I am providing the block, all the default adapters are not used, and I need to specify them myself? |
That's correct, Faraday uses the default_connection if no block is provided, which consists of the :url_encoded middleware and the :net_http adapter (unless that have been changed, which can also be done). Providing a block will replace that default stack with yours. The adapter will still be added automatically if Faraday detects that is missing from the custom block 👍 |
Finally wrapped work on this, so happy to close the issue. One final note, for anyone else that might have stumbled on this: I couldn't see POST requests retrying, but then realised by default,
So in my case, it ended up looking like this: Faraday.new(url: connection_url, request: { timeout: 3 }) do |f|
f.request :url_encoded
f.request :retry, {
max: 4,
interval: 0.05,
interval_randomness: 0.5,
backoff_factor: 2,
exceptions: [Faraday::TimeoutError, Faraday::ConnectionFailed],
methods: %i[get post]
} |
Basic Info
Issue description
I am trying to figure out how to make retry adapted work. I managed to get it working on a simple
GET
request, but when I am trying to use it with POST requests, I get an error. Using a regular connection, like this:Faraday.new(url: 'www.google.com', request: { timeout: 3, open_timeout: 1 })
, doesn't produce any errorsSteps to reproduce
connection.post("test", action: 'get_data')
The text was updated successfully, but these errors were encountered: