From 2b2fc6f1e692a72b8c46ad87d8f6272cef741d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 11 Dec 2022 15:10:16 +0100 Subject: [PATCH] Dont throw an exception, if we can not retrieve an currency exchange rate, but show an meaningful flash message --- .../AdminPages/CurrencyController.php | 5 +++-- templates/AdminPages/CurrencyAdmin.html.twig | 2 +- translations/messages.en.xlf | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Controller/AdminPages/CurrencyController.php b/src/Controller/AdminPages/CurrencyController.php index 0d6182e6..010200ca 100644 --- a/src/Controller/AdminPages/CurrencyController.php +++ b/src/Controller/AdminPages/CurrencyController.php @@ -39,6 +39,7 @@ use App\Services\LogSystem\TimeTravel; use App\Services\StructuralElementRecursionHelper; use Doctrine\ORM\EntityManagerInterface; use Exchanger\Exception\ChainException; +use Exchanger\Exception\Exception; use Exchanger\Exception\UnsupportedCurrencyPairException; use Omines\DataTablesBundle\DataTableFactory; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -117,8 +118,8 @@ class CurrencyController extends BaseAdminController try { $this->exchangeRateUpdater->update($entity); $this->addFlash('info', 'currency.edit.exchange_rate_updated.success'); - } catch (ChainException $exception) { - $exception = $exception->getExceptions()[0]; + } catch (Exception $exception) { + //$exception = $exception->getExceptions()[0]; if ($exception instanceof UnsupportedCurrencyPairException || false !== stripos($exception->getMessage(), 'supported')) { $this->addFlash('error', 'currency.edit.exchange_rate_update.unsupported_currency'); } else { diff --git a/templates/AdminPages/CurrencyAdmin.html.twig b/templates/AdminPages/CurrencyAdmin.html.twig index 45e02d4a..5cc28457 100644 --- a/templates/AdminPages/CurrencyAdmin.html.twig +++ b/templates/AdminPages/CurrencyAdmin.html.twig @@ -20,7 +20,7 @@ {{ form_row(form.exchange_rate) }} {% if form.update_exchange_rate is defined %} - {{ form_row(form.update_exchange_rate, {attr: {class: 'btn-link'}}) }} + {{ form_row(form.update_exchange_rate, {attr: {class: 'btn-info'}}) }} {% endif %} {% if entity.inverseExchangeRate %} diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index d10f8379..e2b4299d 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -9923,5 +9923,23 @@ Element 3 IPN + + + currency.edit.update_rate + Retrieve exchange rate + + + + + currency.edit.exchange_rate_update.unsupported_currency + The currency is unsupported by the exchange rate provider. Check your exchange rate provider configuration. + + + + + currency.edit.exchange_rate_update.generic_error + Unable to retrieve the exchange rate. Check your exchange rate provider configuration. + +