1 |
67c41231
|
Filip Jani
|
<?php
|
2 |
|
|
|
3 |
f115c8b5
|
Filip Jani
|
namespace App\FrontModule\Presenters;
|
4 |
67c41231
|
Filip Jani
|
|
5 |
|
|
use Nette;
|
6 |
|
|
use Nette\Application\Responses;
|
7 |
|
|
use Nette\Http;
|
8 |
|
|
use Tracy\ILogger;
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
final class ErrorPresenter implements Nette\Application\IPresenter
|
12 |
|
|
{
|
13 |
|
|
use Nette\SmartObject;
|
14 |
|
|
|
15 |
|
|
/** @var ILogger */
|
16 |
|
|
private $logger;
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
public function __construct(ILogger $logger)
|
20 |
|
|
{
|
21 |
|
|
$this->logger = $logger;
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
public function run(Nette\Application\Request $request)
|
26 |
|
|
{
|
27 |
|
|
$exception = $request->getParameter('exception');
|
28 |
|
|
|
29 |
|
|
if ($exception instanceof Nette\Application\BadRequestException) {
|
30 |
|
|
list($module, , $sep) = Nette\Application\Helpers::splitName($request->getPresenterName());
|
31 |
|
|
return new Responses\ForwardResponse($request->setPresenterName($module . $sep . 'Error4xx'));
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
$this->logger->log($exception, ILogger::EXCEPTION);
|
35 |
|
|
return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse) {
|
36 |
|
|
if (preg_match('#^text/html(?:;|$)#', $httpResponse->getHeader('Content-Type'))) {
|
37 |
|
|
require __DIR__ . '/templates/Error/500.phtml';
|
38 |
|
|
}
|
39 |
|
|
});
|
40 |
|
|
}
|
41 |
|
|
}
|