Skip to content

Commit

Permalink
Error4xxPresenter: handles 405 error
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 14, 2024
1 parent c354140 commit 14b830f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
15 changes: 9 additions & 6 deletions app/Presenters/Error4xxPresenter.php
Expand Up @@ -12,10 +12,9 @@
*/
final class Error4xxPresenter extends Nette\Application\UI\Presenter
{
public function startup(): void
protected function checkHttpMethod(): void
{
parent::startup();
// ensure the request is a forward (internal redirect)
// allow access via all HTTP methods and ensure the request is a forward (internal redirect)
if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
$this->error();
}
Expand All @@ -24,8 +23,12 @@ public function startup(): void

public function renderDefault(Nette\Application\BadRequestException $exception): void
{
// load the template corresponding to the HTTP code
$file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
$this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
// renders the appropriate error template based on the HTTP status code
$code = $exception->getCode();
$file = is_file($file = __DIR__ . "/templates/Error/$code.latte")
? $file
: __DIR__ . '/templates/Error/4xx.latte';
$this->template->httpCode = $code;
$this->template->setFile($file);
}
}
6 changes: 0 additions & 6 deletions app/Presenters/templates/Error/405.latte

This file was deleted.

2 changes: 2 additions & 0 deletions app/Presenters/templates/Error/4xx.latte
Expand Up @@ -2,3 +2,5 @@
<h1 n:block=title>Oops...</h1>

<p>Your browser sent a request that this server could not understand or process.</p>

<p><small>error {$httpCode}</small></p>

0 comments on commit 14b830f

Please sign in to comment.