From 1b722b32ecc76e5173d1369685f265ab8cab0d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Kr=C5=A1ka?= Date: Sat, 31 Aug 2024 01:52:26 +0200 Subject: [PATCH] resolve error code --- app/Modules/Fykos/DefaultModule/ErrorPresenter.php | 4 ++++ app/Modules/Fykos/DefaultModule/templates/Error/410.latte | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/Modules/Fykos/DefaultModule/ErrorPresenter.php b/app/Modules/Fykos/DefaultModule/ErrorPresenter.php index 28560389..684aac2d 100644 --- a/app/Modules/Fykos/DefaultModule/ErrorPresenter.php +++ b/app/Modules/Fykos/DefaultModule/ErrorPresenter.php @@ -23,13 +23,17 @@ public function injectLogger(ILogger $logger): void public function renderDefault(\Throwable $exception): void { if ($exception instanceof BadRequestException) { + $code = $exception->getCode(); + // specifically return 410 instead of 404 for these paths if (in_array($this->getHttpRequest()->getUrl()->getPath(), ['/prezentace'])) { $code = 410; $this->getHttpResponse()->setCode(410); } + // load template 403.latte or 404.latte or ... 4xx.latte $this->setView(in_array($code, [403, 404, 405, 410, 500, 503]) ? (string)$code : '4xx'); + // log to access.log $this->logger->log( "HTTP code $code: {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}", diff --git a/app/Modules/Fykos/DefaultModule/templates/Error/410.latte b/app/Modules/Fykos/DefaultModule/templates/Error/410.latte index 9568a4f4..3e821d98 100644 --- a/app/Modules/Fykos/DefaultModule/templates/Error/410.latte +++ b/app/Modules/Fykos/DefaultModule/templates/Error/410.latte @@ -8,10 +8,12 @@ {switch $language->value} {case 'cs'}

Požadovaná stránka se již na webu nenachází.

+

Můžete přejít na hlavní stránku.

error 410

{default}

The page you requested has been taken off the site.

+

Visit the front page.

error 410

{/switch}