From 0bc2d40d9b011266e5b6a9597759b54b6439b3db Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 4 Nov 2025 20:48:58 +0100 Subject: [PATCH] Don't throw error, report it. --- app/Http/Controllers/AttachmentController.php | 11 ++--- .../Auth/ForgotPasswordController.php | 4 +- .../Controllers/Auth/RegisterController.php | 6 +-- .../Auth/ResetPasswordController.php | 4 +- app/Http/Controllers/ReportController.php | 12 +++--- .../views/{error.twig => error-old.twig} | 0 resources/views/errors/error.blade.php | 42 +++++++++++++++++++ 7 files changed, 61 insertions(+), 18 deletions(-) rename resources/views/{error.twig => error-old.twig} (100%) create mode 100644 resources/views/errors/error.blade.php diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 2741d94812..6e7e573e98 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -95,7 +95,7 @@ class AttachmentController extends Controller /** * Download attachment to PC. * - * @return LaravelResponse + * @return LaravelResponse|View * * @throws FireflyException */ @@ -121,8 +121,8 @@ class AttachmentController extends Controller return $response; } - - 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')); } /** @@ -194,7 +194,7 @@ class AttachmentController extends Controller * * @throws FireflyException */ - public function view(Attachment $attachment): LaravelResponse + public function view(Attachment $attachment): LaravelResponse|View { if ($this->repository->exists($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')); } } diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index a945fc7879..d3f996c6f4 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -73,7 +73,7 @@ class ForgotPasswordController extends Controller $message = sprintf('Cannot reset password when authenticating over "%s".', config('firefly.authentication_guard')); Log::error($message); - return view('error', compact('message')); + return view('errors.error', compact('message')); } // validate host header. @@ -138,7 +138,7 @@ class ForgotPasswordController extends Controller if ('web' !== 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? diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index a36e65e8bc..ea1e8619f1 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -158,12 +158,12 @@ class RegisterController extends Controller if (true === $allowRegistration) { $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) { $message = 'Invalid code.'; - return view('error', compact('message')); + return view('errors.error', compact('message')); } $email = $request->old('email'); @@ -189,7 +189,7 @@ class RegisterController extends Controller if (false === $allowRegistration) { $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'); diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 714d98bf32..b52ae8e0e7 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -80,7 +80,7 @@ class ResetPasswordController extends Controller if ('web' !== 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 = [ @@ -127,7 +127,7 @@ class ResetPasswordController extends Controller if ('web' !== 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? diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index eb82e859d9..46506681d6 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -82,7 +82,7 @@ class ReportController extends Controller public function auditReport(Collection $accounts, Carbon $start, Carbon $end) { 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(); $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) { 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(); $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) { 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(); $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) { 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(); @@ -336,7 +336,7 @@ class ReportController extends Controller } 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) { @@ -361,7 +361,7 @@ class ReportController extends Controller public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) { 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(); $start->endOfDay(); // end of day so the final balance is at the end of that day. diff --git a/resources/views/error.twig b/resources/views/error-old.twig similarity index 100% rename from resources/views/error.twig rename to resources/views/error-old.twig diff --git a/resources/views/errors/error.blade.php b/resources/views/errors/error.blade.php new file mode 100644 index 0000000000..12a061bfce --- /dev/null +++ b/resources/views/errors/error.blade.php @@ -0,0 +1,42 @@ +@extends('layout.v2.error') +@section('status_code','') +@section('status','Error message') +@section('sub_title', trans('errors.error_occurred')) +@section('content') +
+
+

+ {{ trans('errors.error_not_recoverable') }} +

+

+ {{ $message }} +

+
+
+
+
+

+ {{ trans('errors.more_info') }} +

+

+ {!! trans('errors.collect_info') !!} + {!! trans('errors.collect_info_more') !!} +

+

+ {{ trans('errors.github_help') }} +

+

+ {!! trans('errors.github_instructions') !!} +

+
    +
  1. {{ trans('errors.use_search') }}
  2. +
  3. {!! trans('errors.include_info', ['link' => route('debug') ]) !!}
  4. +
  5. {{ trans('errors.tell_more') }}
  6. +
  7. {{ trans('errors.include_logs') }}
  8. +
  9. {{ trans('errors.what_did_you_do') }}
  10. +
+
+
+@endsection + +