Skip to content

Commit 8b85410

Browse files
JaZotaylorotwell
andauthored
[11.x] Document when method of ThrottlesExceptions middleware (laravel#9551)
* Document `when` method of ThrottlesExceptions middleware * Update queues.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0df96b2 commit 8b85410

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

queues.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,23 @@ Internally, this middleware uses Laravel's cache system to implement rate limiti
656656
return [(new ThrottlesExceptions(10, 10))->by('key')];
657657
}
658658

659+
By default, this middleware will throttle every exception. You can modify this behaviour by invoking the `when` method when attaching the middleware to your job. The exception will then only be throttled if closure provided to the `when` method returns `true`:
660+
661+
use Illuminate\Http\Client\HttpClientException;
662+
use Illuminate\Queue\Middleware\ThrottlesExceptions;
663+
664+
/**
665+
* Get the middleware the job should pass through.
666+
*
667+
* @return array<int, object>
668+
*/
669+
public function middleware(): array
670+
{
671+
return [(new ThrottlesExceptions(10, 10))->when(
672+
fn (Throwable $throwable) => $throwable instanceof HttpClientException
673+
)];
674+
}
675+
659676
> [!NOTE]
660677
> If you are using Redis, you may use the `Illuminate\Queue\Middleware\ThrottlesExceptionsWithRedis` middleware, which is fine-tuned for Redis and more efficient than the basic exception throttling middleware.
661678

0 commit comments

Comments
 (0)