Skip to content

Commit

Permalink
used nette/application 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 11, 2024
1 parent 634f647 commit fdcb032
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
9 changes: 2 additions & 7 deletions app/Presenters/Error4xxPresenter.php
Expand Up @@ -12,13 +12,8 @@
*/
final class Error4xxPresenter extends Nette\Application\UI\Presenter
{
protected function checkHttpMethod(): void
{
// 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();
}
}
// allow access via all HTTP methods
public array $allowedMethods = [];


public function renderDefault(Nette\Application\BadRequestException $exception): void
Expand Down
Expand Up @@ -13,8 +13,12 @@
/**
* Handles uncaught exceptions and errors, and logs them.
*/
final class ErrorPresenter implements Nette\Application\IPresenter
final class Error5xxPresenter implements Nette\Application\IPresenter
{
// allow access via all HTTP methods
public array $allowedMethods = [];


public function __construct(
private ILogger $logger,
) {
Expand All @@ -23,16 +27,11 @@ public function __construct(

public function run(Nette\Application\Request $request): Nette\Application\Response
{
// Log the exception
$exception = $request->getParameter('exception');

// If the exception is a 4xx HTTP error, forward to the Error4xxPresenter
if ($exception instanceof Nette\Application\BadRequestException) {
[$module, , $sep] = Nette\Application\Helpers::splitName($request->getPresenterName());
return new Responses\ForwardResponse($request->setPresenterName($module . $sep . 'Error4xx'));
}

// Log the exception and display a generic error message to the user
$this->logger->log($exception, ILogger::EXCEPTION);

// Display a generic error message to the user
return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse): void {
if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) {
require __DIR__ . '/templates/Error/500.phtml';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -6,7 +6,7 @@
"license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
"require": {
"php": ">= 8.1",
"nette/application": "^3.2",
"nette/application": "^3.2.1",
"nette/bootstrap": "^3.2",
"nette/caching": "^3.2",
"nette/database": "^3.2",
Expand Down
7 changes: 4 additions & 3 deletions config/common.neon
Expand Up @@ -2,9 +2,10 @@ parameters:


application:
errorPresenter: Error
mapping:
*: App\*Module\Presenters\*Presenter
errorPresenter:
4xx: Error4xx
5xx: Error5xx
mapping: App\*Module\Presenters\*Presenter


database:
Expand Down

0 comments on commit fdcb032

Please sign in to comment.