mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Catch and verify various errors
This commit is contained in:
@@ -99,18 +99,18 @@ abstract class Controller extends BaseController
|
||||
foreach ($dates as $field) {
|
||||
try {
|
||||
$date = request()->query->get($field);
|
||||
} catch(BadRequestException $e) {
|
||||
} catch (BadRequestException $e) {
|
||||
Log::error(sprintf('Request field "%s" contains a non-scalar value. Value set to NULL.', $field));
|
||||
Log::error($e->getMessage());
|
||||
$value = null;
|
||||
}
|
||||
$obj = null;
|
||||
$obj = null;
|
||||
if (null !== $date) {
|
||||
try {
|
||||
$obj = Carbon::parse($date);
|
||||
} catch (InvalidDateException|InvalidFormatException $e) {
|
||||
// don't care
|
||||
app('log')->warning(sprintf('Ignored invalid date "%s" in API controller parameter check: %s', $date, $e->getMessage()));
|
||||
app('log')->warning(sprintf('Ignored invalid date "%s" in API controller parameter check: %s', substr($date, 0, 20), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
$bag->set($field, $obj);
|
||||
@@ -121,7 +121,7 @@ abstract class Controller extends BaseController
|
||||
foreach ($integers as $integer) {
|
||||
try {
|
||||
$value = request()->query->get($integer);
|
||||
} catch(BadRequestException $e) {
|
||||
} catch (BadRequestException $e) {
|
||||
Log::error(sprintf('Request field "%s" contains a non-scalar value. Value set to NULL.', $integer));
|
||||
Log::error($e->getMessage());
|
||||
$value = null;
|
||||
@@ -144,8 +144,8 @@ abstract class Controller extends BaseController
|
||||
{
|
||||
$sortParameters = [];
|
||||
try {
|
||||
$param = (string)request()->query->get('sort');
|
||||
} catch(BadRequestException $e) {
|
||||
$param = (string)request()->query->get('sort');
|
||||
} catch (BadRequestException $e) {
|
||||
Log::error('Request field "sort" contains a non-scalar value. Value set to NULL.');
|
||||
Log::error($e->getMessage());
|
||||
$param = '';
|
||||
|
@@ -69,7 +69,7 @@ class DestroyController extends Controller
|
||||
$this->unused = $request->boolean('unused', false);
|
||||
switch ($objects) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('This endpoint can\'t handle object "%s"', $objects));
|
||||
throw new FireflyException(sprintf('200033: This endpoint can\'t handle object "%s"', $objects));
|
||||
case 'budgets':
|
||||
$this->destroyBudgets();
|
||||
break;
|
||||
|
@@ -28,6 +28,7 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
@@ -37,6 +38,7 @@ use Illuminate\Http\JsonResponse;
|
||||
class DestroyController extends Controller
|
||||
{
|
||||
private CurrencyRepositoryInterface $repository;
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
/**
|
||||
* CurrencyRepository constructor.
|
||||
@@ -49,6 +51,7 @@ class DestroyController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
|
@@ -73,7 +73,7 @@ class AttemptController extends Controller
|
||||
public function index(Webhook $webhook, WebhookMessage $message): JsonResponse
|
||||
{
|
||||
if ($message->webhook_id !== $webhook->id) {
|
||||
throw new FireflyException('Webhook and webhook message are no match');
|
||||
throw new FireflyException('200040: Webhook and webhook message are no match');
|
||||
}
|
||||
|
||||
$manager = $this->getManager();
|
||||
@@ -112,10 +112,10 @@ class AttemptController extends Controller
|
||||
public function show(Webhook $webhook, WebhookMessage $message, WebhookAttempt $attempt): JsonResponse
|
||||
{
|
||||
if ($message->webhook_id !== $webhook->id) {
|
||||
throw new FireflyException('Webhook and webhook message are no match');
|
||||
throw new FireflyException('200040: Webhook and webhook message are no match');
|
||||
}
|
||||
if ($attempt->webhook_message_id !== $message->id) {
|
||||
throw new FireflyException('Webhook message and webhook attempt are no match');
|
||||
throw new FireflyException('200041: Webhook message and webhook attempt are no match');
|
||||
}
|
||||
|
||||
$manager = $this->getManager();
|
||||
|
@@ -91,10 +91,10 @@ class DestroyController extends Controller
|
||||
public function destroyAttempt(Webhook $webhook, WebhookMessage $message, WebhookAttempt $attempt): JsonResponse
|
||||
{
|
||||
if ($message->webhook_id !== $webhook->id) {
|
||||
throw new FireflyException('Webhook and webhook message are no match');
|
||||
throw new FireflyException('200040: Webhook and webhook message are no match');
|
||||
}
|
||||
if ($attempt->webhook_message_id !== $message->id) {
|
||||
throw new FireflyException('Webhook message and webhook attempt are no match');
|
||||
throw new FireflyException('200041: Webhook message and webhook attempt are no match');
|
||||
}
|
||||
|
||||
$this->repository->destroyAttempt($attempt);
|
||||
@@ -119,7 +119,7 @@ class DestroyController extends Controller
|
||||
public function destroyMessage(Webhook $webhook, WebhookMessage $message): JsonResponse
|
||||
{
|
||||
if ($message->webhook_id !== $webhook->id) {
|
||||
throw new FireflyException('Webhook and webhook message are no match');
|
||||
throw new FireflyException('200040: Webhook and webhook message are no match');
|
||||
}
|
||||
$this->repository->destroyMessage($message);
|
||||
app('preferences')->mark();
|
||||
|
@@ -103,7 +103,7 @@ class MessageController extends Controller
|
||||
public function show(Webhook $webhook, WebhookMessage $message): JsonResponse
|
||||
{
|
||||
if ($message->webhook_id !== $webhook->id) {
|
||||
throw new FireflyException('Webhook and webhook message are no match');
|
||||
throw new FireflyException('200040: Webhook and webhook message are no match');
|
||||
}
|
||||
|
||||
$manager = $this->getManager();
|
||||
|
@@ -94,18 +94,18 @@ class Controller extends BaseController
|
||||
foreach ($dates as $field) {
|
||||
try {
|
||||
$date = request()->query->get($field);
|
||||
} catch(BadRequestException $e) {
|
||||
} catch (BadRequestException $e) {
|
||||
Log::error(sprintf('Request field "%s" contains a non-scalar value. Value set to NULL.', $field));
|
||||
Log::error($e->getMessage());
|
||||
$value = null;
|
||||
}
|
||||
$obj = null;
|
||||
$obj = null;
|
||||
if (null !== $date) {
|
||||
try {
|
||||
$obj = Carbon::parse($date);
|
||||
} catch (InvalidDateException|InvalidFormatException $e) {
|
||||
// don't care
|
||||
app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', $date, $e->getMessage()));
|
||||
app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr($date, 0, 20), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
$bag->set($field, $obj);
|
||||
@@ -115,7 +115,7 @@ class Controller extends BaseController
|
||||
foreach ($integers as $integer) {
|
||||
try {
|
||||
$value = request()->query->get($integer);
|
||||
} catch(BadRequestException $e) {
|
||||
} catch (BadRequestException $e) {
|
||||
Log::error(sprintf('Request field "%s" contains a non-scalar value. Value set to NULL.', $integer));
|
||||
Log::error($e->getMessage());
|
||||
$value = null;
|
||||
|
Reference in New Issue
Block a user