Skip to content

Commit

Permalink
Avoid retrying by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akihikodaki committed Oct 19, 2024
1 parent 9ae04b8 commit db53675
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,22 @@ x-ratelimit-reset: "1377205443"

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

### Retrying

If you want to retry requests, use `Octokit::Middleware::Retry`.

It uses [Faraday Retry gem] for Faraday 2.x. Add the gem to your Gemfile

```ruby
gem 'faraday-retry'
```

Next, insert `Octokit::Middleware::Retry` before `Octokit::Response::RaiseError`:

```ruby
Octokit.middleware.insert Octokit::Response::RaiseError, Octokit::Middleware::Retry
```

### Caching

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

[retry]: https://github.com/lostisland/faraday-retry
[cache]: https://github.com/sourcelevel/faraday-http-cache
[faraday]: https://github.com/lostisland/faraday

Expand Down
10 changes: 0 additions & 10 deletions lib/octokit/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ module Default

# Default Faraday middleware stack
MIDDLEWARE = Faraday::RackBuilder.new do |builder|
# In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
# so we use it only when it's available.
if defined?(Faraday::Request::Retry)
retry_exceptions = Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
builder.use Faraday::Request::Retry, exceptions: retry_exceptions
elsif defined?(Faraday::Retry::Middleware)
retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Octokit::ServerError]
builder.use Faraday::Retry::Middleware, exceptions: retry_exceptions
end

builder.use Octokit::Middleware::FollowRedirects
builder.use Octokit::Response::RaiseError
builder.use Octokit::Response::FeedParser
Expand Down

0 comments on commit db53675

Please sign in to comment.