Skip to content

Commit

Permalink
Log webhook failure reasons.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Sep 20, 2019
1 parent d77e2af commit de8f50c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/CallWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Spatie\WebhookServer\Events\WebhookCallFailedEvent;
use Spatie\WebhookServer\Events\WebhookCallSucceededEvent;

use Illuminate\Support\Facades\Log;

class CallWebhookJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
Expand Down Expand Up @@ -67,15 +69,28 @@ public function handle()
'body' => json_encode($this->payload),
'verify' => $this->verifySsl,
'headers' => $this->headers,
'errors' => false,
]);

if (!Str::startsWith($this->response->getStatusCode(), 2)) {
throw new Exception('Webhook call failed');
throw new Exception(sprintf(
'Call to %s %s failed with status %d',
$this->httpVerb,
$this->webhookUrl,
$this->response->getStatusCode()
));
}

$this->dispatchEvent(WebhookCallSucceededEvent::class);

} catch (Exception $exception) {
// JDJ: Log the exception, so we know what the problem is.

Log::error(sprintf(
'Webhook failure: %s',
$exception->getMessage()
));

/** @var \Spatie\WebhookServer\BackoffStrategy\BackoffStrategy $backoffStrategry */
$backoffStrategy = app($this->backoffStrategyClass);

Expand Down

0 comments on commit de8f50c

Please sign in to comment.