Custom 404 and 405 error pages

This commit is contained in:
Pierre Rudloff 2020-07-15 23:17:23 +02:00
parent 280618bb6b
commit b6b4dad2ec
3 changed files with 24 additions and 1 deletions

View file

@ -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.
*

View file

@ -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(

View file

@ -3,7 +3,6 @@
<main class="main error">
{include file="inc/logo.tpl"}
<h2>{t}An error occurred{/t}</h2>
{t}Please check the URL of your video.{/t}
<p><i>{$error|escape|nl2br}</i></p>
</main>
{include file='inc/footer.tpl'}