From 649924ad6b55f6710bf61cc6218ea19bc8860408 Mon Sep 17 00:00:00 2001 From: Andrew Warren-Love Date: Fri, 10 Dec 2021 12:02:52 +0000 Subject: [PATCH] Include Exception with Laravel queue failures --- .gitignore | 2 ++ src/CallWebhookJob.php | 2 +- tests/CallWebhookJobTest.php | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6dc30fa..849a53f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ +.idea build composer.lock docs vendor coverage .php-cs-fixer.cache +.phpunit.result.cache diff --git a/src/CallWebhookJob.php b/src/CallWebhookJob.php index 5f91b6c..b258244 100644 --- a/src/CallWebhookJob.php +++ b/src/CallWebhookJob.php @@ -113,7 +113,7 @@ public function handle() if ($lastAttempt) { $this->dispatchEvent(FinalWebhookCallFailedEvent::class); - $this->throwExceptionOnFailure ? $this->fail() : $this->delete(); + $this->throwExceptionOnFailure ? $this->fail($exception) : $this->delete(); } } } diff --git a/tests/CallWebhookJobTest.php b/tests/CallWebhookJobTest.php index 79923fa..7fbf826 100644 --- a/tests/CallWebhookJobTest.php +++ b/tests/CallWebhookJobTest.php @@ -3,6 +3,7 @@ namespace Spatie\WebhookServer\Tests; use GuzzleHttp\Client; +use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\TransferStats; use Illuminate\Queue\Events\JobFailed; use Illuminate\Support\Facades\Event; @@ -237,7 +238,11 @@ public function it_s_generate_job_failed_event_if_an_exception_throws_and_throw_ $this->artisan('queue:work --once'); - Event::assertDispatched(JobFailed::class); + Event::assertDispatched(JobFailed::class, function (JobFailed $event) { + $this->assertInstanceOf(ConnectException::class, $event->exception); + + return true; + }); } protected function baseWebhook(): WebhookCall