Added timeout and debugging statuses to webhooks

- Added a user-configurable timeout option to webhooks.
- Added webhook fields for last-call/error datetime, in addition to last
  error string, which are shown on  webhook edit view.

Related to #3122
This commit is contained in:
Dan Brown
2022-01-03 19:42:48 +00:00
parent 6e18620a0a
commit 00eedafbfd
13 changed files with 205 additions and 80 deletions

View File

@ -53,11 +53,16 @@ class WebhookCallTest extends TestCase
Http::fake([
'*' => Http::response('', 500),
]);
$this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']);
$webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']);
$this->assertNull($webhook->last_errored_at);
$this->runEvent(ActivityType::ROLE_CREATE);
$this->assertTrue($logger->hasError('Webhook call to endpoint https://wh.example.com failed with status 500'));
$webhook->refresh();
$this->assertEquals('Response status from endpoint was 500', $webhook->last_error);
$this->assertNotNull($webhook->last_errored_at);
}
public function test_webhook_call_exception_is_caught_and_logged()
@ -65,11 +70,16 @@ class WebhookCallTest extends TestCase
Http::shouldReceive('asJson')->andThrow(new \Exception('Failed to perform request'));
$logger = $this->withTestLogger();
$this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']);
$webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']);
$this->assertNull($webhook->last_errored_at);
$this->runEvent(ActivityType::ROLE_CREATE);
$this->assertTrue($logger->hasError('Webhook call to endpoint https://wh.example.com failed with error "Failed to perform request"'));
$webhook->refresh();
$this->assertEquals('Failed to perform request', $webhook->last_error);
$this->assertNotNull($webhook->last_errored_at);
}
public function test_webhook_call_data_format()