-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHandler.php
More file actions
50 lines (39 loc) · 1.27 KB
/
Handler.php
File metadata and controls
50 lines (39 loc) · 1.27 KB
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
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Rareloop\Lumberjack\Exceptions;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Rareloop\Lumberjack\Application;
use Rareloop\Lumberjack\Facades\Config;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Symfony\Component\Debug\Exception\FlattenException;
use Laminas\Diactoros\Response\HtmlResponse;
class Handler implements HandlerInterface
{
protected $app;
protected $dontReport = [];
public function __construct(Application $app)
{
$this->app = $app;
}
public function report(Exception $e)
{
if ($this->shouldNotReport($e)) {
return;
}
if ($this->app->has('logger')) {
$logger = $this->app->get('logger');
$logger->error($e);
}
}
public function render(ServerRequestInterface $request, Exception $e) : ResponseInterface
{
$e = FlattenException::create($e);
$handler = new SymfonyExceptionHandler(Config::get('app.debug', false));
return new HtmlResponse($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders());
}
protected function shouldNotReport(Exception $e)
{
return in_array(get_class($e), $this->dontReport);
}
}