diff --git a/CHANGELOG.md b/CHANGELOG.md index db4789bcd..68ba12e6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Fixes an issue, where the shiiping callback required the store-api to be exposed. - Fixes an issue, where PayPal order creation and express checkout flows did not use the taxed cart with tax provider processing - Fixes an issue, where PayPal webhooks with a `custom_id` payload that does not contain an `orderTransactionId` could trigger an undefined array key warning +- Fixes an issue, where causes for validation errors were not logged correctly # 8.10.0 - Added Austria to the countries where Pay Later is available diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index 372cf53e8..da067db42 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -3,6 +3,7 @@ - Behebt ein Problem, bei dem der Versand-Callback die Offenlegung der Store-API erforderte - Behebt ein Problem, bei dem die PayPal-Bestellerstellung und Express-Checkout-Flows nicht den besteuerten Warenkorb mit Tax-Provider-Verarbeitung verwendet haben - Behebt ein Problem, bei dem PayPal-Webhooks mit einem `custom_id`-Payload ohne `orderTransactionId` eine Warnung wegen eines undefinierten Array-Keys ausloesen konnten +- Behebt ein Problem, bei dem Ursachen für Validierungsfehler nicht korrekt protokolliert wurden # 8.10.0 - Fügt Österreich zu den Ländern hinzu, in denen „Später bezahlen“ verfügbar ist diff --git a/src/Util/IntrospectionProcessor.php b/src/Util/IntrospectionProcessor.php index 54522bbe9..857a009c0 100644 --- a/src/Util/IntrospectionProcessor.php +++ b/src/Util/IntrospectionProcessor.php @@ -15,6 +15,7 @@ use Shopware\Core\Framework\HttpException; use Shopware\Core\Framework\Log\Package; use Shopware\Core\Framework\ShopwareHttpException; +use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException; use Swag\PayPal\Pos\Api\Exception\PosException; use Swag\PayPal\Pos\Client\AbstractClient as PosAbstractClient; use Swag\PayPal\RestApi\Client\AbstractClient; @@ -140,21 +141,27 @@ protected function getBacktrace(): array */ private function exceptionToContext(\Throwable $exception): array { - $context = [ - 'message' => $exception->getMessage(), - 'class' => $this->traceToClassString($exception->getTrace()[0]), - 'file' => $exception->getFile(), - 'line' => $exception->getLine(), - ]; + $context = ['message' => $exception->getMessage()]; if ($exception instanceof ShopwareHttpException) { $context['parameters'] = $exception->getParameters(); } + if ($exception instanceof ConstraintViolationException) { + foreach ($exception->getViolations() as $violation) { + $context['parameters']['violations'][] = (string) $violation; + } + } + if ($exception instanceof HttpException || $exception instanceof PosException) { $context['errorCode'] = $exception->getErrorCode(); } + // Order class, file and line at the end to make the exception & the most important information more readable in logs + $context['class'] = $this->traceToClassString($exception->getTrace()[0]); + $context['file'] = $exception->getFile(); + $context['line'] = $exception->getLine(); + if ($exception->getPrevious()) { $context['previous'] = $this->exceptionToContext($exception->getPrevious()); } diff --git a/tests/Util/IntrospectionProcessorTest.php b/tests/Util/IntrospectionProcessorTest.php index 681de3154..6c249d3f9 100644 --- a/tests/Util/IntrospectionProcessorTest.php +++ b/tests/Util/IntrospectionProcessorTest.php @@ -12,6 +12,7 @@ use Monolog\LogRecord; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Log\Package; +use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException; use Shopware\Core\Kernel; use Swag\PayPal\Checkout\Payment\Handler\PayPalHandler; use Swag\PayPal\Pos\Api\Exception\PosException; @@ -21,6 +22,8 @@ use Swag\PayPal\RestApi\V2\Resource\OrderResource; use Swag\PayPal\Storefront\Controller\PayPalController; use Swag\PayPal\Util\IntrospectionProcessor; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\ConstraintViolationList; /** * @internal @@ -270,5 +273,23 @@ public static function invokeWithExceptionDataProvider(): \Generator 'errorCode' => 'SWAG_PAYPAL__POS_EXCEPTION', ]], ]; + + yield 'ConstraintViolationException' => [ + ['exception' => new ConstraintViolationException(new ConstraintViolationList([new ConstraintViolation( + 'test message', + 'test message template with {{ type }}', + ['{{ type }}' => 'testParameter'], + '/root', + 'testProperty', + 'VIOLATION_TESTPROPERTY_INVALID' + )]), [])], + ['exception' => [ + 'message' => 'Caught 1 violation errors.', + 'parameters' => [ + 'count' => 1, + 'violations' => ["/root.testProperty:\n test message"], + ], + ]], + ]; } }