Skip to content

Provide the seconds until retry in @throttle rate limit errors - #2830

Open
officialasishkumar wants to merge 1 commit into
nuwave:masterfrom
officialasishkumar:throttle-retry-after
Open

officialasishkumar wants to merge 1 commit into
nuwave:masterfrom
officialasishkumar:throttle-retry-after

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Resolves #2450

  • Added or updated tests
  • Documented user facing changes

Changes

When @throttle rejects a field, the error now tells clients when they may retry:

{
  "errors": [
    {
      "message": "Rate limit for Query.foo exceeded. Try again later.",
      "extensions": {
        "retryAfter": 42
      }
    }
  ]
}

retryAfter is the number of seconds until the field is accessible again, taken from RateLimiter::availableIn() for the limit that was exceeded.
That is the same value Laravel's ThrottleRequests middleware sends in the Retry-After header.
For named limiters that return several limits, it belongs to the first exceeded limit, as in ThrottleRequests.

RateLimitException implements ProvidesExtensions and takes the seconds as an optional second constructor argument.
The message stays the same, and an exception created without the seconds has no extensions, so existing code that throws or asserts it keeps working.

Breaking changes

None.

Changelog

Added

  • Provide the seconds until clients may retry in extensions.retryAfter of @throttle rate limit errors

When `@throttle` rejects a field, clients only got the message "Try
again later." without knowing when they may actually retry, since the
decay time depends on the configured limiter.

`RateLimitException` now implements `ProvidesExtensions` and accepts the
number of seconds until the field is accessible again. `@throttle` fills
it from the rate limiter's `availableIn()` for the limit that was
exceeded, which is what Laravel's `ThrottleRequests` middleware sends in
the `Retry-After` header. Clients find it in `extensions.retryAfter` of
the error. The message and constructor stay compatible, the extension is
omitted when the exception is created without a value.

Resolves nuwave#2450
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T20:16:55.841159Z 109c63d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@officialasishkumar

Copy link
Copy Markdown
Contributor Author

The failing PHPStan on ... and highest dependencies jobs are unrelated to this change.
phpstan/phpstan 2.4.0 was released after the last green run on master and reports 14 method.alreadyNarrowedType errors for assertInstanceOf() in DeferDBTest, PaginatedRelationLoaderTest and SubscriptionTest, which this PR does not touch.
I get the same errors when running PHPStan on master with the latest dependencies.
The runner then crashes while printing PHPStan's output, so those jobs have no logs.
PHPUnit, PHPStan with the lowest dependencies and the benchmarks pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using throttle directive how can the client be informed when they can retry again etc.

1 participant