Skip to content

Commit a55934a

Browse files
authored
ACP-2626 Return error response in case of no handler was executed. (#2)
1 parent 37b186f commit a55934a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Spryker/Zed/AppWebhook/Business/WebhookHandler/WebhookHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function handleWebhook(WebhookRequestTransfer $webhookRequestTransfer, We
2929
$webhookResponseTransfer = $webhookHandlerPlugin->handleWebhook($webhookRequestTransfer, $webhookResponseTransfer);
3030
}
3131

32+
if ($webhookResponseTransfer->getIsSuccessful() === null) {
33+
$webhookResponseTransfer
34+
->setIsSuccessful(false)
35+
->setMessage(sprintf('The webhook was not handled by any of the registered plugins. WebhookRequestTransfer: %s', json_encode($webhookRequestTransfer->toArray())));
36+
}
37+
3238
return $webhookResponseTransfer;
3339
}
3440
}

tests/SprykerTest/Glue/AppWebhookBackendApi/RestApi/AppWebhookApiTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ public function testGivenAGlueRequestWithoutContentWhenTheRequestIsHandledThenAH
5454
$this->assertSame('POST content is required.', $glueResponseTransfer->getErrors()[0]->getMessage());
5555
}
5656

57+
public function testGivenAValidGlueRequestWhenTheRequestIsNotHandledByAnyOfTheAttachedPluginsThenAnExceptionIsThrownHttpStatus400IsReturnedTogetherWithAMessageInTheGlueResponseTransfer(): void
58+
{
59+
// Arrange
60+
$glueRequestTransfer = new GlueRequestTransfer();
61+
$glueRequestTransfer
62+
->setContent('{"key": "value"}')
63+
->setPath('/webhooks');
64+
65+
$webhooksController = new WebhooksController();
66+
67+
// Act
68+
$glueResponseTransfer = $webhooksController->postAction($glueRequestTransfer);
69+
70+
// Assert
71+
$this->assertSame(Response::HTTP_BAD_REQUEST, $glueResponseTransfer->getHttpStatus());
72+
$this->assertCount(1, $glueResponseTransfer->getErrors());
73+
}
74+
5775
public function testGivenAValidGlueRequestWhenTheRequestIsHandledAndTheWebhookResponseIsSuccessfulThenAHttpStatus200IsReturnedInTheGlueResponseTransfer(): void
5876
{
5977
// Arrange

0 commit comments

Comments
 (0)