From 98c174e7b4c430627c1456392dcda907b8d4228f Mon Sep 17 00:00:00 2001 From: Gytautas Date: Wed, 26 Jun 2024 14:20:01 +0300 Subject: [PATCH 1/4] PIPRES-445: HTTP status handling improvements --- .php-cs-fixer.dist.php | 15 ------------ Makefile | 3 +-- changelog.md | 3 +++ controllers/front/webhook.php | 44 ++++++++++++++++++++++------------- 4 files changed, 32 insertions(+), 33 deletions(-) delete mode 100644 .php-cs-fixer.dist.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 8d68a2263..000000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,15 +0,0 @@ -setUsingCache(true) - ->getFinder() - ->in(__DIR__) - ->exclude('translations') - ->exclude('mails') - ->exclude('libraries') - ->exclude('vendor') - ->exclude('upgrade'); - -return $config; diff --git a/Makefile b/Makefile index 7c3ace459..194247360 100755 --- a/Makefile +++ b/Makefile @@ -90,8 +90,7 @@ npm-package-install: prepare-zip: composer install --no-dev --optimize-autoloader --classmap-authoritative composer dump-autoload --no-dev --optimize --classmap-authoritative - cp .github/.htaccess vendor/.htaccess - rm -rf .git .docker .editorconfig .github tests .php-cs-fixer.php Makefile cypress .docker cypress.config.js cypress.env.json docker-compose*.yml .gitignore bin codeception.yml package-lock.json package.json .php_cs.dist .php-cs-fixer.dist + rm -rf .git .docker .editorconfig .github tests .php-cs-fixer.php Makefile cypress .docker cypress.config.js cypress.env.json docker-compose*.yml .gitignore bin codeception.yml package-lock.json package.json .php_cs.dist .php-cs-fixer.dist .php-cs-fixer.dist.php diff --git a/changelog.md b/changelog.md index 09a8211bc..24953f1bd 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ # Changelog # +## Changes in release 6.2.2 ## ++ Error handling improvements + ## Changes in release 6.2.1 ## + Ideal v2 payment method improvement diff --git a/controllers/front/webhook.php b/controllers/front/webhook.php index fa2710aa3..6b245fe23 100644 --- a/controllers/front/webhook.php +++ b/controllers/front/webhook.php @@ -11,8 +11,10 @@ */ use Mollie\Adapter\ToolsAdapter; +use Mollie\Api\Exceptions\ApiException; use Mollie\Controller\AbstractMollieController; use Mollie\Errors\Http\HttpStatusCode; +use Mollie\Exception\TransactionException; use Mollie\Handler\ErrorHandler\ErrorHandler; use Mollie\Infrastructure\Response\JsonResponse; use Mollie\Logger\PrestaLoggerInterface; @@ -50,9 +52,6 @@ public function initContent(): void /** @var PrestaLoggerInterface $logger */ $logger = $this->module->getService(PrestaLoggerInterface::class); - /** @var ErrorHandler $errorHandler */ - $errorHandler = $this->module->getService(ErrorHandler::class); - /** @var ToolsAdapter $tools */ $tools = $this->module->getService(ToolsAdapter::class); @@ -95,20 +94,12 @@ public function initContent(): void try { $this->executeWebhook($transactionId); + } catch (ApiException $exception) { + $this->handleException($exception, HttpStatusCode::HTTP_BAD_REQUEST, 'Api request failed'); + } catch (TransactionException $exception) { + $this->handleException($exception, $exception->getCode(), 'Failed to handle transaction'); } catch (\Throwable $exception) { - $logger->error('Failed to handle webhook', [ - 'Exception message' => $exception->getMessage(), - 'Exception code' => $exception->getCode(), - ]); - - $errorHandler->handle($exception, $exception->getCode(), false); - - $this->releaseLock(); - - $this->ajaxResponse(JsonResponse::error( - $this->module->l('Failed to handle webhook', self::FILE_NAME), - $exception->getCode() - )); + $this->handleException($exception, HttpStatusCode::HTTP_BAD_REQUEST, 'Failed to handle webhook'); } $this->releaseLock(); @@ -158,4 +149,25 @@ private function setContext(int $cartId): void $this->context->cart = $cart; } + + private function handleException(\Throwable $exception, int $httpStatusCode, string $logMessage): void + { + /** @var PrestaLoggerInterface $logger */ + $logger = $this->module->getService(PrestaLoggerInterface::class); + + /** @var ErrorHandler $errorHandler */ + $errorHandler = $this->module->getService(ErrorHandler::class); + + $logger->error($logMessage, [ + 'Exception message' => $exception->getMessage(), + 'Exception code' => $httpStatusCode + ]); + + $errorHandler->handle($exception, $httpStatusCode, false); + $this->releaseLock(); + $this->ajaxResponse(JsonResponse::error( + $this->module->l('Failed to handle webhook', self::FILE_NAME), + $httpStatusCode + )); + } } From 1ecdcdc5fc3410b80bc49f8f3cb6db57f2c1b5de Mon Sep 17 00:00:00 2001 From: Gytautas Date: Wed, 26 Jun 2024 14:22:22 +0300 Subject: [PATCH 2/4] cs fixer file reverted --- .php-cs-fixer.dist.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .php-cs-fixer.dist.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 000000000..59646bbb0 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,15 @@ +setUsingCache(true) + ->getFinder() + ->in(__DIR__) + ->exclude('translations') + ->exclude('mails') + ->exclude('libraries') + ->exclude('vendor') + ->exclude('upgrade'); + +return $config; \ No newline at end of file From 3b88829bd666f87e077daf94f67a68b23ec7b049 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 8 Jul 2024 13:43:04 +0300 Subject: [PATCH 3/4] php cs fixer fix --- controllers/front/webhook.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/webhook.php b/controllers/front/webhook.php index 6b245fe23..abca3b115 100644 --- a/controllers/front/webhook.php +++ b/controllers/front/webhook.php @@ -150,7 +150,7 @@ private function setContext(int $cartId): void $this->context->cart = $cart; } - private function handleException(\Throwable $exception, int $httpStatusCode, string $logMessage): void + private function handleException(Throwable $exception, int $httpStatusCode, string $logMessage): void { /** @var PrestaLoggerInterface $logger */ $logger = $this->module->getService(PrestaLoggerInterface::class); @@ -160,7 +160,7 @@ private function handleException(\Throwable $exception, int $httpStatusCode, str $logger->error($logMessage, [ 'Exception message' => $exception->getMessage(), - 'Exception code' => $httpStatusCode + 'Exception code' => $httpStatusCode, ]); $errorHandler->handle($exception, $httpStatusCode, false); From dfccc8cb3480945833cbb4f76d3c4d714e4f4539 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 8 Jul 2024 14:05:23 +0300 Subject: [PATCH 4/4] cs fixer --- .php-cs-fixer.dist.php | 2 +- Makefile | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 59646bbb0..8d68a2263 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -12,4 +12,4 @@ ->exclude('vendor') ->exclude('upgrade'); -return $config; \ No newline at end of file +return $config; diff --git a/Makefile b/Makefile index 194247360..de3a68b13 100755 --- a/Makefile +++ b/Makefile @@ -91,7 +91,3 @@ prepare-zip: composer install --no-dev --optimize-autoloader --classmap-authoritative composer dump-autoload --no-dev --optimize --classmap-authoritative rm -rf .git .docker .editorconfig .github tests .php-cs-fixer.php Makefile cypress .docker cypress.config.js cypress.env.json docker-compose*.yml .gitignore bin codeception.yml package-lock.json package.json .php_cs.dist .php-cs-fixer.dist .php-cs-fixer.dist.php - - - -