From 4a3ebac562ff8ba122e948eb5dc73e2df2a1e952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 2 Mar 2023 10:06:41 +0100 Subject: [PATCH] throw runtime error with static pages only if debug --- app/Http/Controllers/Fo/StaticPageController.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Fo/StaticPageController.php b/app/Http/Controllers/Fo/StaticPageController.php index 3ea2e21..6a32ef2 100644 --- a/app/Http/Controllers/Fo/StaticPageController.php +++ b/app/Http/Controllers/Fo/StaticPageController.php @@ -33,12 +33,12 @@ class StaticPageController extends Controller /** * Display a static page * - * @param \Illuminate\Http\Request $request * @param \App\Models\Site\StaticPage $static_page_front + * @param \Illuminate\Http\Request $request * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory * @throws \RuntimeException If the static page type is not handled. */ - public function displayStaticPage(Request $request, StaticPage $static_page_front) + public function displayStaticPage(StaticPage $static_page_front, Request $request) { $static_page = $static_page_front; switch ($static_page->type) { @@ -53,7 +53,10 @@ class StaticPageController extends Controller return view('theme::pages.static-page', compact('static_page')); case StaticPageType::crud(): default: - throw new \RuntimeException("Unhandled static page {$static_page->type->label}"); + if (\config('app.debug')) { + throw new \RuntimeException("Unhandled static page {$static_page->type->label}"); + } + \abort(404); } } @@ -67,7 +70,10 @@ class StaticPageController extends Controller public function displayCrudStaticPage(StaticPage $static_page) { if (!$static_page->type->equals(StaticPageType::crud())) { - throw new \RuntimeException("Unhandled static page {$static_page->type->label}"); + if (\config('app.debug')) { + throw new \RuntimeException("Unhandled static page {$static_page->type->label}"); + } + \abort(404); } return view('theme::pages.static-page', compact('static_page')); }