-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathError5xxPresenter.php
More file actions
39 lines (31 loc) · 953 Bytes
/
Error5xxPresenter.php
File metadata and controls
39 lines (31 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace App\UI\Error\Error5xx;
use Nette;
use Nette\Application\Attributes\Requires;
use Nette\Application\Responses;
use Nette\Http;
use Tracy\ILogger;
/**
* Handles uncaught exceptions and errors, and logs them.
*/
#[Requires(forward: true)]
final class Error5xxPresenter implements Nette\Application\IPresenter
{
public function __construct(
private ILogger $logger,
) {
}
public function run(Nette\Application\Request $request): Nette\Application\Response
{
// Log the exception
$exception = $request->getParameter('exception');
$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__ . '/500.phtml';
}
});
}
}