diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 051918b803..0286b50696 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -37,9 +37,15 @@ class Handler extends ExceptionHandler */ public function render($request, Exception $exception) { + if ($exception instanceof FireflyException) { + + return response()->view('errors.FireflyException', ['exception' => $exception], 500); + } + return parent::render($request, $exception); } + /** * Report or log an exception. * diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index dbbbd7c969..642d7f4f56 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -3,6 +3,7 @@ use Amount; use Auth; use Carbon\Carbon; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Requests\BudgetFormRequest; use FireflyIII\Models\Budget; use FireflyIII\Models\LimitRepetition; @@ -224,16 +225,15 @@ class BudgetController extends Controller /** * @param BudgetRepositoryInterface $repository * @param Budget $budget - * @param LimitRepetition $repetition + * @param LimitRepetition|null $repetition * - * @return \Illuminate\View\View + * @return View + * @throws FireflyException */ public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null) { if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) { - $message = 'Invalid selection.'; - - return view('error', compact('message')); + throw new FireflyException('This budget limit is not part of this budget.'); } $journals = $repository->getJournals($budget, $repetition, 50); diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.php index 2193980f2d..1e2f3259c1 100644 --- a/app/Http/Controllers/CsvController.php +++ b/app/Http/Controllers/CsvController.php @@ -278,13 +278,7 @@ class CsvController extends Controller * field id => field identifier. * ] */ - try { - $options = $this->wizard->showOptions($this->data->getMap()); - } catch (FireflyException $e) { - Log::error($e->getMessage()); - - return view('error', ['message' => $e->getMessage()]); - } + $options = $this->wizard->showOptions($this->data->getMap()); // After these values are prepped, read the actual CSV file $reader = $this->data->getReader(); @@ -321,13 +315,7 @@ class CsvController extends Controller Log::debug('Created importer'); $importer = new Importer; $importer->setData($this->data); - try { - $importer->run(); - } catch (FireflyException $e) { - Log::error('Catch error: ' . $e->getMessage()); - - return view('error', ['message' => $e->getMessage()]); - } + $importer->run(); Log::debug('Done importing!'); $rows = $importer->getRows(); diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 6d1d4ba807..99c52c574c 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -1,6 +1,7 @@ with('message', 'End date cannot be before start date, silly!'); + throw new FireflyException('End date cannot be before start date, silly!') } // lower threshold diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 4081278afb..4c021ce78b 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -7,6 +7,7 @@ use Config; use ExpandedForm; use FireflyIII\Events\TransactionJournalStored; use FireflyIII\Events\TransactionJournalUpdated; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Requests\JournalFormRequest; use FireflyIII\Models\PiggyBank; @@ -141,7 +142,7 @@ class TransactionController extends Controller { // cannot edit opening balance if ($journal->isOpeningBalance()) { - return view('error')->with('message', 'Cannot edit this transaction. Edit the account instead!'); + throw new FireflyException('Cannot edit this transaction (#' . $journal->id . '). Edit the account instead!'); } diff --git a/public/css/firefly.css b/public/css/firefly.css index 898a85a3be..ebcb8946b3 100644 --- a/public/css/firefly.css +++ b/public/css/firefly.css @@ -12,7 +12,13 @@ padding: 0; } - +.error-page { + background: #d2d6de; +} +.error-box { + width: 460px; + margin: 7% auto; +} /* cursors */ .rule-triggers {cursor:move;} diff --git a/resources/views/errors/FireflyException.twig b/resources/views/errors/FireflyException.twig index 282a8b08ee..c11c212d30 100644 --- a/resources/views/errors/FireflyException.twig +++ b/resources/views/errors/FireflyException.twig @@ -48,7 +48,7 @@

- Unfortunately, this error was not recoverable. Firefly III broke. + Unfortunately, this error was not recoverable. Firefly III broke. The error is:

{{ exception.getMessage |default('General unknown errror') }}