mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Improve error handling in API.
This commit is contained in:
@@ -98,15 +98,15 @@ class AttachmentController extends Controller
|
|||||||
public function download(Attachment $attachment): LaravelResponse
|
public function download(Attachment $attachment): LaravelResponse
|
||||||
{
|
{
|
||||||
if (false === $attachment->uploaded) {
|
if (false === $attachment->uploaded) {
|
||||||
throw new FireflyException(trans('api.error_no_upload'));
|
throw new FireflyException('200000: File has not been uploaded (yet).');
|
||||||
}
|
}
|
||||||
if (0 === $attachment->size) {
|
if (0 === $attachment->size) {
|
||||||
throw new FireflyException(trans('api.error_no_upload'));
|
throw new FireflyException('200000: File has not been uploaded (yet).');
|
||||||
}
|
}
|
||||||
if ($this->repository->exists($attachment)) {
|
if ($this->repository->exists($attachment)) {
|
||||||
$content = $this->repository->getContent($attachment);
|
$content = $this->repository->getContent($attachment);
|
||||||
if ('' === $content) {
|
if ('' === $content) {
|
||||||
throw new FireflyException(trans('api.error_no_upload'));
|
throw new FireflyException('200002: File is empty (zero bytes).');
|
||||||
}
|
}
|
||||||
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ class AttachmentController extends Controller
|
|||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
throw new FireflyException(trans('api.error_file_lost'));
|
throw new FireflyException('200003: File does not exist.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -212,7 +212,6 @@ class BillController extends Controller
|
|||||||
public function store(BillRequest $request): JsonResponse
|
public function store(BillRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$bill = $this->repository->store($request->getAll());
|
$bill = $this->repository->store($request->getAll());
|
||||||
if (null !== $bill) {
|
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
|
||||||
/** @var BillTransformer $transformer */
|
/** @var BillTransformer $transformer */
|
||||||
@@ -223,9 +222,6 @@ class BillController extends Controller
|
|||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||||
}
|
}
|
||||||
throw new FireflyException(trans('api.error_store_bill')); // @codeCoverageIgnore
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show all transactions.
|
* Show all transactions.
|
||||||
|
@@ -188,7 +188,6 @@ class BudgetController extends Controller
|
|||||||
public function store(BudgetRequest $request): JsonResponse
|
public function store(BudgetRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$budget = $this->repository->store($request->getAll());
|
$budget = $this->repository->store($request->getAll());
|
||||||
if (null !== $budget) {
|
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
|
||||||
/** @var BudgetTransformer $transformer */
|
/** @var BudgetTransformer $transformer */
|
||||||
@@ -199,8 +198,6 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||||
}
|
}
|
||||||
throw new FireflyException(trans('api.error_store_budget')); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
|
@@ -165,7 +165,7 @@ class BudgetLimitController extends Controller
|
|||||||
$data = $request->getAll();
|
$data = $request->getAll();
|
||||||
$budget = $this->repository->findNull($data['budget_id']);
|
$budget = $this->repository->findNull($data['budget_id']);
|
||||||
if (null === $budget) {
|
if (null === $budget) {
|
||||||
throw new FireflyException(trans('api.error_unknown_budget'));
|
throw new FireflyException('200004: Budget does not exist.');
|
||||||
}
|
}
|
||||||
$data['budget'] = $budget;
|
$data['budget'] = $budget;
|
||||||
$budgetLimit = $this->blRepository->storeBudgetLimit($data);
|
$budgetLimit = $this->blRepository->storeBudgetLimit($data);
|
||||||
|
@@ -152,7 +152,6 @@ class CategoryController extends Controller
|
|||||||
public function store(CategoryRequest $request): JsonResponse
|
public function store(CategoryRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$category = $this->repository->store($request->getAll());
|
$category = $this->repository->store($request->getAll());
|
||||||
if (null !== $category) {
|
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
|
||||||
/** @var CategoryTransformer $transformer */
|
/** @var CategoryTransformer $transformer */
|
||||||
@@ -163,8 +162,6 @@ class CategoryController extends Controller
|
|||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||||
}
|
}
|
||||||
throw new FireflyException(trans('api.error_store_new_category')); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show all transactions.
|
* Show all transactions.
|
||||||
|
@@ -57,7 +57,7 @@ class ConfigurationController extends Controller
|
|||||||
$admin = auth()->user();
|
$admin = auth()->user();
|
||||||
|
|
||||||
if (!$this->repository->hasRole($admin, 'owner')) {
|
if (!$this->repository->hasRole($admin, 'owner')) {
|
||||||
throw new FireflyException(trans('api.error_no_access')); // @codeCoverageIgnore
|
throw new FireflyException('200005: You need the "owner" role to do this.'); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
@@ -313,10 +313,10 @@ class CurrencyController extends Controller
|
|||||||
|
|
||||||
if (!$this->userRepository->hasRole($admin, 'owner')) {
|
if (!$this->userRepository->hasRole($admin, 'owner')) {
|
||||||
// access denied:
|
// access denied:
|
||||||
throw new FireflyException(trans('api.error_no_access_ownership')); // @codeCoverageIgnore
|
throw new FireflyException('200005: You need the "owner" role to do this.'); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
if ($this->repository->currencyInUse($currency)) {
|
if ($this->repository->currencyInUse($currency)) {
|
||||||
throw new FireflyException(trans('api.error_no_access_currency_in_use')); // @codeCoverageIgnore
|
throw new FireflyException('200006: Currency in use.'); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$this->repository->destroy($currency);
|
$this->repository->destroy($currency);
|
||||||
|
|
||||||
@@ -574,8 +574,6 @@ class CurrencyController extends Controller
|
|||||||
public function store(CurrencyRequest $request): JsonResponse
|
public function store(CurrencyRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$currency = $this->repository->store($request->getAll());
|
$currency = $this->repository->store($request->getAll());
|
||||||
|
|
||||||
if (null !== $currency) {
|
|
||||||
if (true === $request->boolean('default')) {
|
if (true === $request->boolean('default')) {
|
||||||
app('preferences')->set('currencyPreference', $currency->code);
|
app('preferences')->set('currencyPreference', $currency->code);
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
@@ -592,9 +590,6 @@ class CurrencyController extends Controller
|
|||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||||
}
|
}
|
||||||
throw new FireflyException(trans('api.error_store_new_currency')); // @codeCoverageIgnore
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show all transactions.
|
* Show all transactions.
|
||||||
|
@@ -24,10 +24,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Factory;
|
namespace FireflyIII\Factory;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Services\Internal\Support\BillServiceTrait;
|
use FireflyIII\Services\Internal\Support\BillServiceTrait;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +57,7 @@ class BillFactory
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Bill|null
|
* @return Bill|null
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function create(array $data): ?Bill
|
public function create(array $data): ?Bill
|
||||||
{
|
{
|
||||||
@@ -64,10 +67,9 @@ class BillFactory
|
|||||||
$currency = $factory->find((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
$currency = $factory->find((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
||||||
|
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
// use default currency:
|
|
||||||
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
$bill = Bill::create(
|
$bill = Bill::create(
|
||||||
[
|
[
|
||||||
@@ -84,8 +86,12 @@ class BillFactory
|
|||||||
'active' => $data['active'] ?? true,
|
'active' => $data['active'] ?? true,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
} catch(QueryException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
Log::error($e->getTraceAsString());
|
||||||
|
throw new FireflyException('400000: Could not store bill.');
|
||||||
|
}
|
||||||
|
|
||||||
// update note:
|
|
||||||
if (isset($data['notes'])) {
|
if (isset($data['notes'])) {
|
||||||
$this->updateNote($bill, $data['notes']);
|
$this->updateNote($bill, $data['notes']);
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +24,10 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Factory;
|
namespace FireflyIII\Factory;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +64,7 @@ class CategoryFactory
|
|||||||
* @param null|string $categoryName
|
* @param null|string $categoryName
|
||||||
*
|
*
|
||||||
* @return Category|null
|
* @return Category|null
|
||||||
*
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category
|
public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category
|
||||||
{
|
{
|
||||||
@@ -88,13 +90,17 @@ class CategoryFactory
|
|||||||
if (null !== $category) {
|
if (null !== $category) {
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return Category::create(
|
return Category::create(
|
||||||
[
|
[
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'name' => $categoryName,
|
'name' => $categoryName,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
} catch (QueryException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
throw new FireflyException('400003: Could not store new category.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -27,6 +27,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Factory;
|
namespace FireflyIII\Factory;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -51,9 +52,10 @@ class TransactionCurrencyFactory
|
|||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency|null
|
* @return TransactionCurrency
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function create(array $data): ?TransactionCurrency
|
public function create(array $data): TransactionCurrency
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
/** @var TransactionCurrency $currency */
|
/** @var TransactionCurrency $currency */
|
||||||
@@ -69,6 +71,7 @@ class TransactionCurrencyFactory
|
|||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
$result = null;
|
$result = null;
|
||||||
Log::error(sprintf('Could not create new currency: %s', $e->getMessage()));
|
Log::error(sprintf('Could not create new currency: %s', $e->getMessage()));
|
||||||
|
throw new FireflyException('400004: Could not store new currency.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\Repositories\Bill;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\BillFactory;
|
use FireflyIII\Factory\BillFactory;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Note;
|
use FireflyIII\Models\Note;
|
||||||
@@ -662,9 +663,10 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Bill|null
|
* @return Bill
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(array $data): ?Bill
|
public function store(array $data): Bill
|
||||||
{
|
{
|
||||||
/** @var BillFactory $factory */
|
/** @var BillFactory $factory */
|
||||||
$factory = app(BillFactory::class);
|
$factory = app(BillFactory::class);
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Bill;
|
namespace FireflyIII\Repositories\Bill;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
@@ -266,9 +267,10 @@ interface BillRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Bill|null
|
* @return Bill
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(array $data): ?Bill;
|
public function store(array $data): Bill;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Bill $bill
|
* @param Bill $bill
|
||||||
|
@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Budget;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||||
@@ -32,6 +33,7 @@ use FireflyIII\Models\RuleAction;
|
|||||||
use FireflyIII\Models\RuleTrigger;
|
use FireflyIII\Models\RuleTrigger;
|
||||||
use FireflyIII\Services\Internal\Destroy\BudgetDestroyService;
|
use FireflyIII\Services\Internal\Destroy\BudgetDestroyService;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@@ -269,16 +271,20 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Budget
|
* @return Budget
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(array $data): Budget
|
public function store(array $data): Budget
|
||||||
{
|
{
|
||||||
$newBudget = new Budget(
|
try {
|
||||||
|
$newBudget = Budget::create(
|
||||||
[
|
[
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$newBudget->save();
|
} catch(QueryException $e) {
|
||||||
|
throw new FireflyException('400002: Could not store budget.');
|
||||||
|
}
|
||||||
|
|
||||||
return $newBudget;
|
return $newBudget;
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Budget;
|
namespace FireflyIII\Repositories\Budget;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -132,6 +133,7 @@ interface BudgetRepositoryInterface
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Budget
|
* @return Budget
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(array $data): Budget;
|
public function store(array $data): Budget;
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ namespace FireflyIII\Repositories\Category;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\CategoryFactory;
|
use FireflyIII\Factory\CategoryFactory;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||||
@@ -239,6 +240,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Category
|
* @return Category
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(array $data): Category
|
public function store(array $data): Category
|
||||||
{
|
{
|
||||||
@@ -246,7 +248,13 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
$factory = app(CategoryFactory::class);
|
$factory = app(CategoryFactory::class);
|
||||||
$factory->setUser($this->user);
|
$factory->setUser($this->user);
|
||||||
|
|
||||||
return $factory->findOrCreate(null, $data['name']);
|
$category = $factory->findOrCreate(null, $data['name']);
|
||||||
|
|
||||||
|
if (null === $category) {
|
||||||
|
throw new FireflyException(sprintf('400003: Could not store new category with name "%s"', $data['name']));
|
||||||
|
}
|
||||||
|
return $category;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Category;
|
namespace FireflyIII\Repositories\Category;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -117,7 +118,7 @@ interface CategoryRepositoryInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
* @throws FireflyException
|
||||||
* @return Category
|
* @return Category
|
||||||
*/
|
*/
|
||||||
public function store(array $data): Category;
|
public function store(array $data): Category;
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Currency;
|
namespace FireflyIII\Repositories\Currency;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||||
use FireflyIII\Models\AccountMeta;
|
use FireflyIII\Models\AccountMeta;
|
||||||
use FireflyIII\Models\AvailableBudget;
|
use FireflyIII\Models\AvailableBudget;
|
||||||
@@ -489,14 +490,20 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency|null
|
* @return TransactionCurrency
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(array $data): ?TransactionCurrency
|
public function store(array $data): TransactionCurrency
|
||||||
{
|
{
|
||||||
/** @var TransactionCurrencyFactory $factory */
|
/** @var TransactionCurrencyFactory $factory */
|
||||||
$factory = app(TransactionCurrencyFactory::class);
|
$factory = app(TransactionCurrencyFactory::class);
|
||||||
|
$result = $factory->create($data);
|
||||||
|
|
||||||
return $factory->create($data);
|
if (null === $result) {
|
||||||
|
throw new FireflyException('400004: Could not store new currency.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -234,9 +234,9 @@ interface CurrencyRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency|null
|
* @return TransactionCurrency
|
||||||
*/
|
*/
|
||||||
public function store(array $data): ?TransactionCurrency;
|
public function store(array $data): TransactionCurrency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionCurrency $currency
|
* @param TransactionCurrency $currency
|
||||||
|
Reference in New Issue
Block a user