diff --git a/queues.md b/queues.md index 94a48954b0..affb97025e 100644 --- a/queues.md +++ b/queues.md @@ -1428,6 +1428,64 @@ $this->fail('Something went wrong.'); > [!NOTE] > For more information on failed jobs, check out the [documentation on dealing with job failures](#dealing-with-failed-jobs). + +#### Failing Jobs on Specific Exceptions + +The `FailOnException` [job middleware](#job-middleware) allows you to short-circuit retries when specific exceptions are thrown. This allows retrying on transient exceptions such as external API errors, but failing the job permanently on persistent exceptions, such as a user's permissions being revoked: + +```php +authorize('sync-chat-history'); + + $response = Http::throw()->get( + "https://chat.laravel.test/?user={$user->uuid} + "); + + + // ... + } + + /** + * Get the middleware the job should pass through. + */ + public function middleware(): array + { + return [ + new FailOnException([AuthorizationException::class]) + ]; + } +} +``` + ## Job Batching