mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +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
|
||||
{
|
||||
@@ -84,8 +85,9 @@ class StoreByDateRequest extends FormRequest
|
||||
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$to = Amount::getTransactionCurrencyByCode((string)$key);
|
||||
if (null === $to) {
|
||||
} 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'));
|
||||
|
||||
|
@@ -288,10 +288,8 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
if (array_key_exists('transaction_currency_id', $data) && is_int($data['transaction_currency_id'])) {
|
||||
$currency = Amount::getTransactionCurrencyById($data['transaction_currency_id']);
|
||||
if (null !== $currency) {
|
||||
$piggyBank->transaction_currency_id = $currency->id;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('target_amount', $data) && '' !== $data['target_amount']) {
|
||||
$piggyBank->target_amount = $data['target_amount'];
|
||||
|
@@ -33,6 +33,7 @@ use FireflyIII\Support\Facades\Steam;
|
||||
use FireflyIII\Support\Singleton\PreferencesSingleton;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use NumberFormatter;
|
||||
|
||||
/**
|
||||
@@ -126,7 +127,9 @@ class Amount
|
||||
}
|
||||
$currency = TransactionCurrency::find($currencyId);
|
||||
if (null === $currency) {
|
||||
throw new FireflyException(sprintf('Could not find a transaction currency with ID #%d', $currencyId));
|
||||
$message = sprintf('Could not find a transaction currency with ID #%d', $currencyId);
|
||||
Log::error($message);
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
$instance->setPreference($key, $currency);
|
||||
return $currency;
|
||||
@@ -143,7 +146,9 @@ class Amount
|
||||
}
|
||||
$currency = TransactionCurrency::whereCode($code)->first();
|
||||
if (null === $currency) {
|
||||
throw new FireflyException(sprintf('Could not find a transaction currency with code "%s"', $code));
|
||||
$message = sprintf('Could not find a transaction currency with code "%s"', $code);
|
||||
Log::error($message);
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
$instance->setPreference($key, $currency);
|
||||
return $currency;
|
||||
|
@@ -267,9 +267,6 @@ class ExchangeRateConverter
|
||||
}
|
||||
$euro = Amount::getTransactionCurrencyByCode('EUR');
|
||||
++$this->queryCount;
|
||||
if (null === $euro) {
|
||||
throw new FireflyException('Cannot find EUR in system, cannot do currency conversion.');
|
||||
}
|
||||
$cache->store($euro->id);
|
||||
|
||||
return $euro->id;
|
||||
|
@@ -25,10 +25,10 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountBalance;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -79,8 +79,7 @@ class AccountBalanceCalculator
|
||||
->orderBy('transaction_journals.order', 'desc')
|
||||
->orderBy('transaction_journals.id', 'asc')
|
||||
->orderBy('transaction_journals.description', 'asc')
|
||||
->orderBy('transactions.amount', 'asc')
|
||||
;
|
||||
->orderBy('transactions.amount', 'asc');
|
||||
if ($accounts->count() > 0) {
|
||||
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
|
||||
}
|
||||
@@ -139,8 +138,7 @@ class AccountBalanceCalculator
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('transactions.amount', 'DESC')
|
||||
->where('transactions.account_id', $accountId)
|
||||
;
|
||||
->where('transactions.account_id', $accountId);
|
||||
$notBefore->startOfDay();
|
||||
$query->where('transaction_journals.date', '<', $notBefore);
|
||||
|
||||
@@ -171,9 +169,9 @@ class AccountBalanceCalculator
|
||||
* @var array $balance
|
||||
*/
|
||||
foreach ($currencies as $currencyId => $balance) {
|
||||
/** @var null|TransactionCurrency $currency */
|
||||
try {
|
||||
$currency = Amount::getTransactionCurrencyById($currencyId);
|
||||
if (null === $currency) {
|
||||
} catch (FireflyException) {
|
||||
Log::error(sprintf('Could not find currency #%d, will not save account balance.', $currencyId));
|
||||
|
||||
continue;
|
||||
|
@@ -524,8 +524,9 @@ class Steam
|
||||
$singleton = PreferencesSingleton::getInstance();
|
||||
foreach ($others as $key => $amount) {
|
||||
$preference = $singleton->getPreference($key);
|
||||
try {
|
||||
$currency = $preference ?? Amount::getTransactionCurrencyByCode($key);
|
||||
if (null === $currency) {
|
||||
} catch (FireflyException) {
|
||||
continue;
|
||||
}
|
||||
if (null === $preference) {
|
||||
|
Reference in New Issue
Block a user