Skip to content

Commit

Permalink
Catch terminals API exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin-Magmodules committed Aug 17, 2023
1 parent 14b4db9 commit 63b3401
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Block/Form/Pointofsale.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Block\Form;
use Mollie\Api\Resources\Terminal;
use Mollie\Payment\Logger\MollieLogger;
use Mollie\Payment\Service\Mollie\MollieApiClient;

/**
Expand All @@ -26,15 +27,21 @@ class Pointofsale extends Form
* @var MollieApiClient
*/
private $mollieApiClient;
/**
* @var MollieLogger
*/
private $logger;

public function __construct(
Context $context,
MollieApiClient $mollieApiClient,
MollieLogger $logger,
array $data = []
) {
parent::__construct($context, $data);

$this->mollieApiClient = $mollieApiClient;
$this->logger = $logger;
}

/**
Expand All @@ -47,14 +54,18 @@ public function __construct(
* }
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getTerminals(): array
{
$storeId = $this->_storeManager->getStore()->getId();

$mollieApiClient = $this->mollieApiClient->loadByStore((int)$storeId);
$terminals = $mollieApiClient->terminals->page();
try {
$mollieApiClient = $this->mollieApiClient->loadByStore((int)$storeId);
$terminals = $mollieApiClient->terminals->page();
} catch (\Mollie\Api\Exceptions\ApiException $exception) {
$this->logger->addErrorLog('terminals', $exception->getMessage());
return [];
}

$output = [];
/** @var Terminal $terminal */
Expand Down

0 comments on commit 63b3401

Please sign in to comment.