From 775f8c5edb92ceab321c2ba48431f396375077bd Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Sat, 7 Mar 2020 12:37:46 +0100 Subject: [PATCH] Fix webhook action for Kirby 3 --- src/Actions/WebhookAction.php | 9 +++++---- tests/Actions/WebhookActionTest.php | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Actions/WebhookAction.php b/src/Actions/WebhookAction.php index 4d5e94f..b1dfd61 100644 --- a/src/Actions/WebhookAction.php +++ b/src/Actions/WebhookAction.php @@ -2,6 +2,7 @@ namespace Uniform\Actions; +use Exception; use Kirby\Toolkit\A; use Kirby\Http\Remote; use Kirby\Toolkit\I18n; @@ -49,10 +50,10 @@ public function perform() $params['headers'] = array_merge(A::get($params, 'headers', []), $headers); - $response = $this->request($url, $params); - - if ($response->error !== 0) { - $this->fail(I18n::translate('uniform-webhook-error').$response->message); + try { + $this->request($url, $params); + } catch (Exception $e) { + $this->fail(I18n::translate('uniform-webhook-error').$e->getMessage()); } } diff --git a/tests/Actions/WebhookActionTest.php b/tests/Actions/WebhookActionTest.php index 572505e..6353684 100644 --- a/tests/Actions/WebhookActionTest.php +++ b/tests/Actions/WebhookActionTest.php @@ -2,7 +2,6 @@ namespace Uniform\Tests\Actions; -use StdClass; use Exception; use Uniform\Form; use Uniform\Tests\TestCase; @@ -89,14 +88,15 @@ public function testProcessData() class WebhookActionStub extends WebhookAction { + public $shouldFail = false; + protected function request($url, $params) { $this->url = $url; $this->params = $params; - $response = new StdClass; - $response->error = isset($this->shouldFail) ? 1 : 0; - $response->message = ''; - return $response; + if ($this->shouldFail) { + throw new Exception; + } } }