Skip to content

Commit

Permalink
Add error handling to data handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Müller committed Jan 10, 2024
1 parent e289f0e commit a80302e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

namespace PayonePayment\Components\DataHandler\OrderActionLog;

use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;

class OrderActionLogDataHandler implements OrderActionLogDataHandlerInterface
{
public function __construct(
protected readonly EntityRepository $orderActionLogRepository
protected readonly EntityRepository $orderActionLogRepository,
protected readonly LoggerInterface $logger
) {
}

Expand Down Expand Up @@ -40,6 +42,13 @@ public function createOrderActionLog(
'requestDateTime' => new \DateTime(),
];

$this->orderActionLogRepository->create([$orderActionLog], $context);
try {
$this->orderActionLogRepository->create([$orderActionLog], $context);
} catch (\Exception $exception) {
$this->logger->error('Failed to create order action log', [
'message' => $exception->getMessage(),
'trace' => $exception->getTraceAsString(),
]);
}
}
}
13 changes: 11 additions & 2 deletions src/Components/DataHandler/WebhookLog/WebhookLogDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

namespace PayonePayment\Components\DataHandler\WebhookLog;

use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;

class WebhookLogDataHandler implements WebhookLogDataHandlerInterface
{
public function __construct(
protected readonly EntityRepository $webhookLogRepository
protected readonly EntityRepository $webhookLogRepository,
protected readonly LoggerInterface $logger
) {
}

Expand All @@ -33,6 +35,13 @@ public function createWebhookLog(
'webhookDateTime' => new \DateTime(),
];

$this->webhookLogRepository->create([$webhookLog], $context);
try {
$this->webhookLogRepository->create([$webhookLog], $context);
} catch (\Exception $exception) {
$this->logger->error('Failed to create webhook log', [
'message' => $exception->getMessage(),
'trace' => $exception->getTraceAsString(),
]);
}
}
}
3 changes: 2 additions & 1 deletion src/DependencyInjection/handler/global_handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@

<service id="PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandler">
<argument type="service" id="payone_payment_order_action_log.repository" />
<argument type="service" id="PayonePayment\Components\ConfigReader\ConfigReaderInterface"/>
<argument type="service" id="PayonePayment\Util\Logger" />
</service>
<service id="PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface" alias="PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandler"/>

<service id="PayonePayment\Components\DataHandler\WebhookLog\WebhookLogDataHandler">
<argument type="service" id="payone_payment_webhook_log.repository" />
<argument type="service" id="PayonePayment\Util\Logger" />
</service>
<service id="PayonePayment\Components\DataHandler\WebhookLog\WebhookLogDataHandlerInterface" alias="PayonePayment\Components\DataHandler\WebhookLog\WebhookLogDataHandler"/>

Expand Down

0 comments on commit a80302e

Please sign in to comment.