Skip to content

Commit

Permalink
PIPRES-445: HTTP status handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GytisZum committed Jun 26, 2024
1 parent b119af5 commit 98c174e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
15 changes: 0 additions & 15 deletions .php-cs-fixer.dist.php

This file was deleted.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 28 additions & 16 deletions controllers/front/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
));
}
}

0 comments on commit 98c174e

Please sign in to comment.