Skip to content

Commit

Permalink
Merge pull request mollie#946 from GytisZum/PIPRES-445/http-status
Browse files Browse the repository at this point in the history
PIPRES-445/http status
  • Loading branch information
GytisZum authored Jul 9, 2024
2 parents 0a51a8e + c7b945c commit ebe09a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ 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
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 ebe09a3

Please sign in to comment.