Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set response on webhook request error? #19

Closed
dmason30 opened this issue Aug 21, 2019 · 1 comment · Fixed by spatie/laravel-webhook-server#16
Closed

Set response on webhook request error? #19

dmason30 opened this issue Aug 21, 2019 · 1 comment · Fixed by spatie/laravel-webhook-server#16

Comments

@dmason30
Copy link

dmason30 commented Aug 21, 2019

I am willing to PR this if needed but I would like to have access to the response even when the webhook call has failed. Guzzle RequestException exceptions have a getResponse method which allows you to get this.

Current code CallWebhookJob

try {
    $this->response = $client->request(...);

   ...
} catch (Exception $exception) {
    /** @var \Spatie\WebhookServer\BackoffStrategy\BackoffStrategy $backoffStrategy */
    $backoffStrategy = app($this->backoffStrategyClass);

    $waitInSeconds = $backoffStrategy->waitInSecondsAfterAttempt($this->attempts());

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

    $this->release($waitInSeconds);
}

Proposed change to CallWebhookJob?
Detect if exception is a RequestException and set the response.

try {
    $this->response = $client->request(...);

   ...
} catch (Exception $exception) {
    
    if ($exception instanceof GuzzleHttp\Exception\RequestException) {
        $this->response = $exception->getResponse();
    }

  ...
}
@freekmurze
Copy link
Member

Thanks for the suggestion. Submit a PR with tests for this. 👍

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 a pull request may close this issue.

2 participants