Skip to content

Commit 3395ed4

Browse files
committedOct 19, 2024
Avoid retrying by default
No retry middleware is included in Faraday 2.x and retrying requires Faraday Retry gem. The default middlware stack used to include a retry middleware only when available, which means the behavior of Octokit implicitly changes depending on to the Faraday version or the presence of Faraday Retry gem. Remove the retry middleware from the default middleware stack to avoid such an implicit behavioral change.
1 parent c892eb3 commit 3395ed4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed
 

‎README.md

+17
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,22 @@ x-ratelimit-reset: "1377205443"
631631

632632
See the [Faraday README][faraday] for more middleware magic.
633633

634+
### Retrying
635+
636+
If you want to retry requests, use `Octokit::Middleware::Retry`.
637+
638+
It uses [Faraday Retry gem] for Faraday 2.x. Add the gem to your Gemfile
639+
640+
```ruby
641+
gem 'faraday-retry'
642+
```
643+
644+
Next, insert `Octokit::Middleware::Retry` before `Octokit::Response::RaiseError`:
645+
646+
```ruby
647+
Octokit.middleware.insert Octokit::Response::RaiseError, Octokit::Middleware::Retry
648+
```
649+
634650
### Caching
635651

636652
If you want to boost performance, stretch your API rate limit, or avoid paying
@@ -655,6 +671,7 @@ Once configured, the middleware will store responses in cache based on ETag
655671
fingerprint and serve those back up for future `304` responses for the same
656672
resource. See the [project README][cache] for advanced usage.
657673

674+
[retry]: https://github.com/lostisland/faraday-retry
658675
[cache]: https://github.com/sourcelevel/faraday-http-cache
659676
[faraday]: https://github.com/lostisland/faraday
660677

‎lib/octokit/default.rb

-10
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ module Default
2323

2424
# Default Faraday middleware stack
2525
MIDDLEWARE = Faraday::RackBuilder.new do |builder|
26-
# In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
27-
# so we use it only when it's available.
28-
if defined?(Faraday::Request::Retry)
29-
retry_exceptions = Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
30-
builder.use Faraday::Request::Retry, exceptions: retry_exceptions
31-
elsif defined?(Faraday::Retry::Middleware)
32-
retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
33-
builder.use Faraday::Retry::Middleware, exceptions: retry_exceptions
34-
end
35-
3626
builder.use Octokit::Middleware::FollowRedirects
3727
builder.use Octokit::Response::RaiseError
3828
builder.use Octokit::Response::FeedParser

0 commit comments

Comments
 (0)
Failed to load comments.