Don't throw error, report it.

This commit is contained in:
James Cole
2025-11-04 20:48:58 +01:00
parent a3eb3bb1a4
commit 0bc2d40d9b
7 changed files with 61 additions and 18 deletions

View File

@@ -95,7 +95,7 @@ class AttachmentController extends Controller
/** /**
* Download attachment to PC. * Download attachment to PC.
* *
* @return LaravelResponse * @return LaravelResponse|View
* *
* @throws FireflyException * @throws FireflyException
*/ */
@@ -121,8 +121,8 @@ class AttachmentController extends Controller
return $response; return $response;
} }
$message = 'Could not find the indicated attachment. The file is no longer there.';
throw new FireflyException('Could not find the indicated attachment. The file is no longer there.'); return view('errors.error', compact('message'));
} }
/** /**
@@ -194,7 +194,7 @@ class AttachmentController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
public function view(Attachment $attachment): LaravelResponse public function view(Attachment $attachment): LaravelResponse|View
{ {
if ($this->repository->exists($attachment)) { if ($this->repository->exists($attachment)) {
$content = $this->repository->getContent($attachment); $content = $this->repository->getContent($attachment);
@@ -223,6 +223,7 @@ class AttachmentController extends Controller
); );
} }
throw new FireflyException('Could not find the indicated attachment. The file is no longer there.'); $message = 'Could not find the indicated attachment. The file is no longer there.';
return view('errors.error', compact('message'));
} }
} }

View File

@@ -73,7 +73,7 @@ class ForgotPasswordController extends Controller
$message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard')); $message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard'));
Log::error($message); Log::error($message);
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
// validate host header. // validate host header.
@@ -138,7 +138,7 @@ class ForgotPasswordController extends Controller
if ('web' !== config('firefly.authentication_guard')) { if ('web' !== config('firefly.authentication_guard')) {
$message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard')); $message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard'));
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
// is allowed to? // is allowed to?

View File

@@ -158,12 +158,12 @@ class RegisterController extends Controller
if (true === $allowRegistration) { if (true === $allowRegistration) {
$message = 'You do not need an invite code on this installation.'; $message = 'You do not need an invite code on this installation.';
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
if (false === $validCode) { if (false === $validCode) {
$message = 'Invalid code.'; $message = 'Invalid code.';
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
$email = $request->old('email'); $email = $request->old('email');
@@ -189,7 +189,7 @@ class RegisterController extends Controller
if (false === $allowRegistration) { if (false === $allowRegistration) {
$message = 'Registration is currently not available. If you are the administrator, you can enable this in the administration.'; $message = 'Registration is currently not available. If you are the administrator, you can enable this in the administration.';
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
$email = $request?->old('email'); $email = $request?->old('email');

View File

@@ -80,7 +80,7 @@ class ResetPasswordController extends Controller
if ('web' !== config('firefly.authentication_guard')) { if ('web' !== config('firefly.authentication_guard')) {
$message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard')); $message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard'));
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
$rules = [ $rules = [
@@ -127,7 +127,7 @@ class ResetPasswordController extends Controller
if ('web' !== config('firefly.authentication_guard')) { if ('web' !== config('firefly.authentication_guard')) {
$message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard')); $message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard'));
return view('error', compact('message')); return view('errors.error', compact('message'));
} }
// is allowed to register? // is allowed to register?

View File

@@ -82,7 +82,7 @@ class ReportController extends Controller
public function auditReport(Collection $accounts, Carbon $start, Carbon $end) public function auditReport(Collection $accounts, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', (string) trans('firefly.end_after_start_date')); return view('errors.error')->with('message', (string) trans('firefly.end_after_start_date'));
} }
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$start->endOfDay(); // end of day so the final balance is at the end of that day. $start->endOfDay(); // end of day so the final balance is at the end of that day.
@@ -115,7 +115,7 @@ class ReportController extends Controller
public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end) public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', (string) trans('firefly.end_after_start_date')); return view('errors.error')->with('message', (string) trans('firefly.end_after_start_date'));
} }
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$start->endOfDay(); // end of day so the final balance is at the end of that day. $start->endOfDay(); // end of day so the final balance is at the end of that day.
@@ -149,7 +149,7 @@ class ReportController extends Controller
public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end) public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', (string) trans('firefly.end_after_start_date')); return view('errors.error')->with('message', (string) trans('firefly.end_after_start_date'));
} }
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$start->endOfDay(); // end of day so the final balance is at the end of that day. $start->endOfDay(); // end of day so the final balance is at the end of that day.
@@ -183,7 +183,7 @@ class ReportController extends Controller
public function defaultReport(Collection $accounts, Carbon $start, Carbon $end) public function defaultReport(Collection $accounts, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', (string) trans('firefly.end_after_start_date')); return view('errors.error')->with('message', (string) trans('firefly.end_after_start_date'));
} }
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
@@ -336,7 +336,7 @@ class ReportController extends Controller
} }
if ($request->getEndDate() < $request->getStartDate()) { if ($request->getEndDate() < $request->getStartDate()) {
return view('error')->with('message', (string) trans('firefly.end_after_start_date')); return view('errors.error')->with('message', (string) trans('firefly.end_after_start_date'));
} }
$url = match ($reportType) { $url = match ($reportType) {
@@ -361,7 +361,7 @@ class ReportController extends Controller
public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{ {
if ($end < $start) { if ($end < $start) {
return view('error')->with('message', (string) trans('firefly.end_after_start_date')); return view('errors.error')->with('message', (string) trans('firefly.end_after_start_date'));
} }
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$start->endOfDay(); // end of day so the final balance is at the end of that day. $start->endOfDay(); // end of day so the final balance is at the end of that day.

View File

@@ -0,0 +1,42 @@
@extends('layout.v2.error')
@section('status_code','')
@section('status','Error message')
@section('sub_title', trans('errors.error_occurred'))
@section('content')
<div class="row">
<div class="col">
<p>
{{ trans('errors.error_not_recoverable') }}
</p>
<p class="text-danger">
{{ $message }}
</p>
</div>
</div>
<div class="row">
<div class="col">
<h4>
{{ trans('errors.more_info') }}
</h4>
<p>
{!! trans('errors.collect_info') !!}
{!! trans('errors.collect_info_more') !!}
</p>
<h4>
{{ trans('errors.github_help') }}
</h4>
<p>
{!! trans('errors.github_instructions') !!}
</p>
<ol>
<li>{{ trans('errors.use_search') }}</li>
<li>{!! trans('errors.include_info', ['link' => route('debug') ]) !!}</li>
<li>{{ trans('errors.tell_more') }}</li>
<li>{{ trans('errors.include_logs') }}</li>
<li>{{ trans('errors.what_did_you_do') }}</li>
</ol>
</div>
</div>
@endsection