From b6b4dad2ec73a1d8dbfb435ff5b9e0fb201637f4 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 15 Jul 2020 23:17:23 +0200 Subject: [PATCH] Custom 404 and 405 error pages --- classes/Controller/FrontController.php | 22 ++++++++++++++++++++++ index.php | 2 ++ templates/error.tpl | 1 - 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/classes/Controller/FrontController.php b/classes/Controller/FrontController.php index 9526c0c..b292e3b 100644 --- a/classes/Controller/FrontController.php +++ b/classes/Controller/FrontController.php @@ -260,6 +260,28 @@ class FrontController extends BaseController return $response->withStatus(StatusCode::HTTP_INTERNAL_SERVER_ERROR); } + /** + * @param Request $request + * @param Response $response + * @return Response + */ + public function notFound(Request $request, Response $response) + { + return $this->displayError($request, $response, $this->localeManager->t('Page not found')) + ->withStatus(StatusCode::HTTP_NOT_FOUND); + } + + /** + * @param Request $request + * @param Response $response + * @return Response + */ + public function notAllowed(Request $request, Response $response) + { + return $this->displayError($request, $response, $this->localeManager->t('Method not allowed')) + ->withStatus(StatusCode::HTTP_METHOD_NOT_ALLOWED); + } + /** * Display an error page. * diff --git a/index.php b/index.php index 9814f47..009d13f 100644 --- a/index.php +++ b/index.php @@ -46,6 +46,8 @@ try { // Error handling. $container['errorHandler'] = [$frontController, 'error']; $container['phpErrorHandler'] = [$frontController, 'error']; + $container['notFoundHandler'] = [$frontController, 'notFound']; + $container['notAllowedHandler'] = [$frontController, 'notAllowed']; // Routes. $app->get( diff --git a/templates/error.tpl b/templates/error.tpl index 98605b8..abc8897 100644 --- a/templates/error.tpl +++ b/templates/error.tpl @@ -3,7 +3,6 @@
{include file="inc/logo.tpl"}

{t}An error occurred{/t}

- {t}Please check the URL of your video.{/t}

{$error|escape|nl2br}

{include file='inc/footer.tpl'}