mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 08:51:12 -06:00
Throw errors instead of abort()
This commit is contained in:
parent
317aa591c3
commit
1a110de597
@ -4,6 +4,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\User;
|
||||
@ -151,7 +152,7 @@ class AuthController extends Controller
|
||||
|
||||
return redirect($this->redirectPath());
|
||||
}
|
||||
abort(500, 'Not a user!');
|
||||
throw new FireflyException('The authenticated user object is invalid.');
|
||||
|
||||
|
||||
return redirect($this->redirectPath());
|
||||
|
@ -3,6 +3,7 @@
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
@ -247,7 +248,7 @@ class JsonController extends Controller
|
||||
{
|
||||
$pref = Preferences::get('tour', true);
|
||||
if (!$pref) {
|
||||
abort(404);
|
||||
throw new FireflyException('Cannot find preference for tour. Exit.');
|
||||
}
|
||||
$headers = ['main-content', 'sidebar-toggle', 'account-menu', 'budget-menu', 'report-menu', 'transaction-menu', 'option-menu', 'main-content-end'];
|
||||
$steps = [];
|
||||
|
@ -6,6 +6,7 @@ namespace FireflyIII\Http\Requests;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Input;
|
||||
|
||||
@ -32,6 +33,7 @@ class JournalFormRequest extends Request
|
||||
public function getJournalData()
|
||||
{
|
||||
$tags = $this->get('tags') ?? '';
|
||||
|
||||
return [
|
||||
'what' => $this->get('what'),
|
||||
'description' => $this->get('description'),
|
||||
@ -86,7 +88,7 @@ class JournalFormRequest extends Request
|
||||
$rules['category'] = 'between:1,255';
|
||||
break;
|
||||
default:
|
||||
abort(500, 'Cannot handle ' . $what);
|
||||
throw new FireflyException('Cannot handle transaction type of type ' . e($what) . '.');
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use DB;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@ -482,7 +483,9 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$existingAccount = Account::firstOrNullEncrypted($searchData);
|
||||
if (!$existingAccount) {
|
||||
Log::error('Account create error: ' . $newAccount->getErrors()->toJson());
|
||||
abort(500);
|
||||
throw new FireflyException(
|
||||
'Cannot create a new account. See also the log files. First error is: ' . e($newAccount->getErrors()->first()) . '.'
|
||||
);
|
||||
}
|
||||
$newAccount = $existingAccount;
|
||||
|
||||
|
@ -6,6 +6,7 @@ namespace FireflyIII\Repositories\Journal;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
@ -349,14 +350,14 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
|
||||
if (is_null($toAccount)) {
|
||||
Log::error('"to"-account is null, so we cannot continue!');
|
||||
abort(500, '"to"-account is null, so we cannot continue!');
|
||||
throw new FireflyException('"to"-account is null, so we cannot continue!');
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
if (is_null($fromAccount)) {
|
||||
Log::error('"from"-account is null, so we cannot continue!');
|
||||
abort(500, '"from"-account is null, so we cannot continue!');
|
||||
throw new FireflyException('"from"-account is null, so we cannot continue!');
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Rules\Actions;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\Domain;
|
||||
@ -24,43 +25,51 @@ class ActionFactory
|
||||
protected static $actionTypes = null;
|
||||
|
||||
/**
|
||||
* Returns the class name to be used for actions with the given name
|
||||
* @param string $actionType
|
||||
* Returns the action for the given type and journal
|
||||
*
|
||||
* @param RuleAction $action
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return ActionInterface
|
||||
*/
|
||||
public static function getActionClass(string $actionType): string {
|
||||
public static function getAction(RuleAction $action, TransactionJournal $journal): ActionInterface
|
||||
{
|
||||
$actionType = $action->action_type;
|
||||
$class = self::getActionClass($actionType);
|
||||
|
||||
return new $class($action, $journal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name to be used for actions with the given name
|
||||
*
|
||||
* @param string $actionType
|
||||
*
|
||||
* @return ActionInterface|string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function getActionClass(string $actionType): string
|
||||
{
|
||||
$actionTypes = self::getActionTypes();
|
||||
|
||||
if (!array_key_exists($actionType, $actionTypes)) {
|
||||
abort(500, 'No such action exists ("' . $actionType . '").');
|
||||
throw new FireflyException('No such action exists ("' . e($actionType) . '").');
|
||||
}
|
||||
|
||||
$class = $actionTypes[$actionType];
|
||||
if (!class_exists($class)) {
|
||||
abort(500, 'Could not instantiate class for rule action type "' . $actionType . '" (' . $class . ').');
|
||||
throw new FireflyException('Could not instantiate class for rule action type "' . e($actionType) . '" (' . e($class) . ').');
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the action for the given type and journal
|
||||
* @param RuleAction $action
|
||||
* @param TransactionJournal $journal
|
||||
* @return ActionInterface
|
||||
*/
|
||||
public static function getAction(RuleAction $action, TransactionJournal $journal): ActionInterface {
|
||||
$actionType = $action->action_type;
|
||||
$class = self::getActionClass($actionType);
|
||||
|
||||
return new $class($action, $journal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map with actiontypes, mapped to the class representing that type
|
||||
*/
|
||||
protected static function getActionTypes() {
|
||||
if( !self::$actionTypes ) {
|
||||
protected static function getActionTypes()
|
||||
{
|
||||
if (!self::$actionTypes) {
|
||||
self::$actionTypes = Domain::getRuleActions();
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Rules\Triggers;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\RuleTrigger;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\Domain;
|
||||
@ -51,13 +52,12 @@ class TriggerFactory
|
||||
$triggerTypes = self::getTriggerTypes();
|
||||
|
||||
if (!array_key_exists($triggerType, $triggerTypes)) {
|
||||
abort(500, 'No such trigger exists ("' . $triggerType . '").');
|
||||
throw new FireflyException('No such trigger exists ("' . e($triggerType) . '").');
|
||||
}
|
||||
|
||||
/** @var TriggerInterface $class */
|
||||
$class = $triggerTypes[$triggerType];
|
||||
if (!class_exists($class)) {
|
||||
abort(500, 'Could not instantiate class for rule trigger type "' . $triggerType . '" (' . $class . ').');
|
||||
throw new FireflyException('Could not instantiate class for rule trigger type "' . e($triggerType) . '" (' . e($class) . ').');
|
||||
}
|
||||
|
||||
return $class;
|
||||
|
Loading…
Reference in New Issue
Block a user