Skip to content

Commit

Permalink
Fix webhook action for Kirby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Mar 7, 2020
1 parent 9ce6bb8 commit 775f8c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/Actions/WebhookAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Uniform\Actions;

use Exception;
use Kirby\Toolkit\A;
use Kirby\Http\Remote;
use Kirby\Toolkit\I18n;
Expand Down Expand Up @@ -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());
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Actions/WebhookActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Uniform\Tests\Actions;

use StdClass;
use Exception;
use Uniform\Form;
use Uniform\Tests\TestCase;
Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 775f8c5

Please sign in to comment.