From e0adf92ca94c9556283d40ab2fcd16a7ff6f35b3 Mon Sep 17 00:00:00 2001 From: m-muxfeld-diw <143803170+m-muxfeld-diw@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:53:31 +0200 Subject: [PATCH] PISHPS-374: extended logging of OrderStateService (#879) * PISHPS-374: extended logging of OrderStateService * PISHPS-374: extended logging of DeliveryTransitionService and TransactionTransitionService * PISHPS-374: catching throwable instead of base exception * PISHPS-374: csfix --- src/Service/Order/OrderStateService.php | 8 +++++-- .../Transition/DeliveryTransitionService.php | 22 ++++++++++++++++++- .../TransactionTransitionService.php | 20 ++++++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/Service/Order/OrderStateService.php b/src/Service/Order/OrderStateService.php index 7be5806da..f36fe2489 100644 --- a/src/Service/Order/OrderStateService.php +++ b/src/Service/Order/OrderStateService.php @@ -2,7 +2,6 @@ namespace Kiener\MolliePayments\Service\Order; -use Exception; use Kiener\MolliePayments\Service\Transition\OrderTransitionServiceInterface; use Kiener\MolliePayments\Setting\MollieSettingStruct; use Psr\Log\LoggerInterface; @@ -72,11 +71,16 @@ public function setOrderState(OrderEntity $order, string $orderState, Context $c } return true; - } catch (Exception $e) { + } catch (\Throwable $e) { $this->logger->error( $e->getMessage(), [ 'function' => 'payment-automate-order-state', + 'order.id' => $order->getId(), + 'order.number' => $order->getOrderNumber(), + 'new.state' => $orderState, + 'old.state' => $currentStatus, + 'trace' => $e->getTraceAsString(), ] ); } diff --git a/src/Service/Transition/DeliveryTransitionService.php b/src/Service/Transition/DeliveryTransitionService.php index 0e5629a9c..154d5a20a 100644 --- a/src/Service/Transition/DeliveryTransitionService.php +++ b/src/Service/Transition/DeliveryTransitionService.php @@ -190,7 +190,27 @@ private function getAvailableTransitions(OrderDeliveryEntity $delivery, Context */ private function performTransition(OrderDeliveryEntity $delivery, string $transitionName, Context $context): void { - $this->transitionService->performTransition(OrderDeliveryDefinition::ENTITY_NAME, $delivery->getId(), $transitionName, $context); + $this->loggerService->debug( + sprintf( + 'Performing transition %s for delivery %s', + $transitionName, + $delivery->getId() + ) + ); + + try { + $this->transitionService->performTransition(OrderDeliveryDefinition::ENTITY_NAME, $delivery->getId(), $transitionName, $context); + } catch (\Throwable $e) { + $this->loggerService->error( + $e->getMessage(), + [ + 'method' => 'delivery-transition-perform-transition', + 'delivery.id' => $delivery->getId(), + 'delivery.payload' => $delivery->jsonSerialize(), + 'transition' => $transitionName + ] + ); + } } /** diff --git a/src/Service/Transition/TransactionTransitionService.php b/src/Service/Transition/TransactionTransitionService.php index 0510788a8..cb0bc8265 100644 --- a/src/Service/Transition/TransactionTransitionService.php +++ b/src/Service/Transition/TransactionTransitionService.php @@ -294,6 +294,24 @@ private function getAvailableTransitions(string $entityId, Context $context): ar private function performTransition(string $entityId, string $transitionName, Context $context): void { - $this->transitionService->performTransition(OrderTransactionDefinition::ENTITY_NAME, $entityId, $transitionName, $context); + $this->logger->debug( + sprintf( + 'Performing transition %s for order transaction %s', + $transitionName, + $entityId + ) + ); + try { + $this->transitionService->performTransition(OrderTransactionDefinition::ENTITY_NAME, $entityId, $transitionName, $context); + } catch (\Throwable $e) { + $this->logger->error( + $e->getMessage(), + [ + 'method' => 'transaction-transition-service-perform-transition', + 'entity.id' => $entityId, + 'transition' => $transitionName + ] + ); + } } }