-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHandler.php
More file actions
58 lines (44 loc) · 1.31 KB
/
Handler.php
File metadata and controls
58 lines (44 loc) · 1.31 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
51
52
53
54
55
56
57
58
<?php
namespace Rareloop\Lumberjack\Exceptions;
use Exception;
use Spatie\Ignition\Ignition;
use Rareloop\Lumberjack\Application;
use Psr\Http\Message\ResponseInterface;
use Rareloop\Lumberjack\Facades\Config;
use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Message\ServerRequestInterface;
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
{
$isDebug = Config::get('app.debug', false) === true;
$ignition = Ignition::make()
->shouldDisplayException($isDebug)
->runningInProductionEnvironment(!$isDebug)
->register();
ob_start();
$ignition->handleException($e);
$html = ob_get_clean();
return new HtmlResponse($html);
}
protected function shouldNotReport(Exception $e)
{
return in_array($e::class, $this->dontReport);
}
}