Skip to content

Firefly III: a personal finances manager

Fix #10687

James Colebb3b06cf0859
diff --git a/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php b/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
index f99939be28..fb8cab1443 100644
--- a/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
@@ -96,7 +96,10 @@ class StoreRequest extends FormRequest
function (Validator $validator): void {
// validate start before end only if both are there.
$data = $validator->getData();
- $currency = $this->getCurrencyFromData($data);
+ $currency = $this->getCurrencyFromData($validator, $data);
+ if(null === $currency) {
+ return;
+ }
$targetAmount = (string) ($data['target_amount'] ?? '0');
$currentAmount = '0';
if (array_key_exists('accounts', $data) && is_array($data['accounts'])) {
@@ -130,7 +133,7 @@ class StoreRequest extends FormRequest
}
}
- private function getCurrencyFromData(array $data): TransactionCurrency
+ private function getCurrencyFromData(Validator $validator, array $data): ?TransactionCurrency
{
if (array_key_exists('transaction_currency_code', $data) && '' !== (string) $data['transaction_currency_code']) {
$currency = TransactionCurrency::whereCode($data['transaction_currency_code'])->first();
@@ -144,7 +147,7 @@ class StoreRequest extends FormRequest
return $currency;
}
}
-
- throw new FireflyException('Unexpected empty currency.');
+ $validator->errors()->add('transaction_currency_id', trans('validation.require_currency_id_code'));
+ return null;
}
}
diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php
index eed095e186..6794b8b8f7 100644
--- a/resources/lang/en_US/validation.php
+++ b/resources/lang/en_US/validation.php
@@ -77,6 +77,7 @@ return [
'at_least_one_repetition' => 'Need at least one repetition.',
'require_repeat_until' => 'Require either a number of repetitions, or an end date (repeat_until). Not both.',
'require_currency_info' => 'The content of this field is invalid without currency information.',
+ 'require_currency_id_code' => 'Please set either "transaction_currency_id" or "transaction_currency_code".',
'not_transfer_account' => 'This account is not an account that can be used for transfers.',
'require_currency_amount' => 'The content of this field is invalid without foreign amount information.',
'require_foreign_currency' => 'This field requires a number',