mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Catch exceptions.
This commit is contained in:
@@ -100,9 +100,6 @@ class StoreController extends Controller
|
||||
$collection = new Collection();
|
||||
foreach ($data['rates'] as $key => $rate) {
|
||||
$to = Amount::getTransactionCurrencyByCode($key);
|
||||
if (null === $to) {
|
||||
continue; // should not happen.
|
||||
}
|
||||
$existing = $this->repository->getSpecificRateOnDate($from, $to, $date);
|
||||
if (null !== $existing) {
|
||||
// update existing rate.
|
||||
|
@@ -24,12 +24,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreByDateRequest extends FormRequest
|
||||
{
|
||||
@@ -49,7 +50,7 @@ class StoreByDateRequest extends FormRequest
|
||||
|
||||
public function getFromCurrency(): TransactionCurrency
|
||||
{
|
||||
return Amount::getTransactionCurrencyByCode((string) $this->get('from'));
|
||||
return Amount::getTransactionCurrencyByCode((string)$this->get('from'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,8 +85,9 @@ class StoreByDateRequest extends FormRequest
|
||||
|
||||
continue;
|
||||
}
|
||||
$to = Amount::getTransactionCurrencyByCode((string) $key);
|
||||
if (null === $to) {
|
||||
try {
|
||||
$to = Amount::getTransactionCurrencyByCode((string)$key);
|
||||
} catch (FireflyException) {
|
||||
$validator->errors()->add(sprintf('rates.%s', $key), trans('validation.invalid_currency_code', ['code' => $key]));
|
||||
}
|
||||
}
|
||||
|
@@ -136,16 +136,10 @@ class StoreRequest extends FormRequest
|
||||
private function getCurrencyFromData(Validator $validator, array $data): ?TransactionCurrency
|
||||
{
|
||||
if (array_key_exists('transaction_currency_code', $data) && '' !== (string) $data['transaction_currency_code']) {
|
||||
$currency = Amount::getTransactionCurrencyByCode((string) $data['transaction_currency_code']);
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
}
|
||||
return Amount::getTransactionCurrencyByCode((string) $data['transaction_currency_code']);
|
||||
}
|
||||
if (array_key_exists('transaction_currency_id', $data) && '' !== (string) $data['transaction_currency_id']) {
|
||||
$currency = Amount::getTransactionCurrencyById((int) $data['transaction_currency_id']);
|
||||
if (null !== $currency) {
|
||||
return $currency;
|
||||
}
|
||||
return Amount::getTransactionCurrencyById((int) $data['transaction_currency_id']);
|
||||
}
|
||||
$validator->errors()->add('transaction_currency_id', trans('validation.require_currency_id_code'));
|
||||
|
||||
|
Reference in New Issue
Block a user