Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Elegant/GoodMethodName:
- total_issues_created
- total_releases_published
- track_request
- untrack_request
- unmask_repos
- update_organization_membership
- user_name_by_id
Expand Down
14 changes: 14 additions & 0 deletions lib/fbe/middleware/rate_limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def call(env)
@lock.synchronize { sync(response_env, env.url.path) }
end
end
rescue StandardError
@lock.synchronize { untrack_request(env.url.path) } unless env.url.path == '/rate_limit'
raise
end

# Returns the remaining requests count tracked by this middleware.
Expand Down Expand Up @@ -91,6 +94,17 @@ def track_request(path = nil)
end
end

# Reverts the counter decrement when the request fails.
def untrack_request(path = nil)
return unless @counter&.positive?
@counter -= 1
if path&.start_with?('/search/')
@searchleft += 1 if @searchleft&.positive?
elsif @remaining&.positive?
@remaining += 1
end
end

# Syncs the internal remaining count from a real API response header.
#
# When the response was served by Faraday::HttpCache from cache
Expand Down
Loading