More consistent error handling.

This commit is contained in:
James Cole 2016-02-06 05:01:34 +01:00
parent 69d0c31ae5
commit 241190c4da
7 changed files with 25 additions and 24 deletions

View File

@ -37,9 +37,15 @@ class Handler extends ExceptionHandler
*/ */
public function render($request, Exception $exception) public function render($request, Exception $exception)
{ {
if ($exception instanceof FireflyException) {
return response()->view('errors.FireflyException', ['exception' => $exception], 500);
}
return parent::render($request, $exception); return parent::render($request, $exception);
} }
/** /**
* Report or log an exception. * Report or log an exception.
* *

View File

@ -3,6 +3,7 @@
use Amount; use Amount;
use Auth; use Auth;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\BudgetFormRequest; use FireflyIII\Http\Requests\BudgetFormRequest;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\LimitRepetition; use FireflyIII\Models\LimitRepetition;
@ -224,16 +225,15 @@ class BudgetController extends Controller
/** /**
* @param BudgetRepositoryInterface $repository * @param BudgetRepositoryInterface $repository
* @param Budget $budget * @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) public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null)
{ {
if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) { if (!is_null($repetition->id) && $repetition->budgetLimit->budget->id != $budget->id) {
$message = 'Invalid selection.'; throw new FireflyException('This budget limit is not part of this budget.');
return view('error', compact('message'));
} }
$journals = $repository->getJournals($budget, $repetition, 50); $journals = $repository->getJournals($budget, $repetition, 50);

View File

@ -278,13 +278,7 @@ class CsvController extends Controller
* field id => field identifier. * field id => field identifier.
* ] * ]
*/ */
try { $options = $this->wizard->showOptions($this->data->getMap());
$options = $this->wizard->showOptions($this->data->getMap());
} catch (FireflyException $e) {
Log::error($e->getMessage());
return view('error', ['message' => $e->getMessage()]);
}
// After these values are prepped, read the actual CSV file // After these values are prepped, read the actual CSV file
$reader = $this->data->getReader(); $reader = $this->data->getReader();
@ -321,13 +315,7 @@ class CsvController extends Controller
Log::debug('Created importer'); Log::debug('Created importer');
$importer = new Importer; $importer = new Importer;
$importer->setData($this->data); $importer->setData($this->data);
try { $importer->run();
$importer->run();
} catch (FireflyException $e) {
Log::error('Catch error: ' . $e->getMessage());
return view('error', ['message' => $e->getMessage()]);
}
Log::debug('Done importing!'); Log::debug('Done importing!');
$rows = $importer->getRows(); $rows = $importer->getRows();

View File

@ -1,6 +1,7 @@
<?php namespace FireflyIII\Http\Controllers; <?php namespace FireflyIII\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
@ -83,8 +84,7 @@ class ReportController extends Controller
{ {
// throw an error if necessary. // throw an error if necessary.
if ($end < $start) { if ($end < $start) {
throw new FireflyException('End date cannot be before start date, silly!')
return view('error')->with('message', 'End date cannot be before start date, silly!');
} }
// lower threshold // lower threshold

View File

@ -7,6 +7,7 @@ use Config;
use ExpandedForm; use ExpandedForm;
use FireflyIII\Events\TransactionJournalStored; use FireflyIII\Events\TransactionJournalStored;
use FireflyIII\Events\TransactionJournalUpdated; use FireflyIII\Events\TransactionJournalUpdated;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Requests\JournalFormRequest; use FireflyIII\Http\Requests\JournalFormRequest;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
@ -141,7 +142,7 @@ class TransactionController extends Controller
{ {
// cannot edit opening balance // cannot edit opening balance
if ($journal->isOpeningBalance()) { 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!');
} }

View File

@ -12,7 +12,13 @@
padding: 0; padding: 0;
} }
.error-page {
background: #d2d6de;
}
.error-box {
width: 460px;
margin: 7% auto;
}
/* cursors */ /* cursors */
.rule-triggers {cursor:move;} .rule-triggers {cursor:move;}

View File

@ -48,7 +48,7 @@
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="col-lg-12 col-md-12 col-sm-12">
<p> <p>
Unfortunately, this error was not recoverable. Firefly III broke. Unfortunately, this error was not recoverable. Firefly III broke. The error is:
</p> </p>
<p class="text-danger"> <p class="text-danger">
{{ exception.getMessage |default('General unknown errror') }} {{ exception.getMessage |default('General unknown errror') }}