|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\App\EventHandlers; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
|
10
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
11
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\App\AccessDeniedException; |
|
13
|
|
|
|
|
14
|
|
|
class LogErrors implements EventSubscriberInterface { |
|
15
|
|
|
|
|
16
|
|
|
private const PRIORITY = -2; |
|
17
|
|
|
|
|
18
|
|
|
private LoggerInterface $logger; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct( LoggerInterface $logger ) { |
|
21
|
|
|
$this->logger = $logger; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public static function getSubscribedEvents() { |
|
25
|
|
|
return [ |
|
26
|
|
|
KernelEvents::EXCEPTION => [ 'onKernelException', self::PRIORITY ] |
|
27
|
|
|
]; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function onKernelException( GetResponseForExceptionEvent $event ): void { |
|
31
|
|
|
$exception = $event->getException(); |
|
32
|
|
|
|
|
33
|
|
|
if ( $exception instanceof AccessDeniedException || $exception instanceof NotFoundHttpException ) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$request = $event->getRequest(); |
|
38
|
|
|
$this->logger->error( |
|
39
|
|
|
$exception->getMessage(), |
|
40
|
|
|
[ |
|
41
|
|
|
'code' => $exception->getCode(), |
|
42
|
|
|
'file' => $exception->getFile(), |
|
43
|
|
|
'line' => $exception->getLine(), |
|
44
|
|
|
'stack_trace' => $exception->getTraceAsString(), |
|
45
|
|
|
'referrer' => $request->headers->get( 'referer' ), |
|
46
|
|
|
'uri' => $request->getRequestUri(), |
|
47
|
|
|
'languages' => $request->getLanguages(), |
|
48
|
|
|
'charsets' => $request->getCharsets(), |
|
49
|
|
|
'content_types' => $request->getAcceptableContentTypes(), |
|
50
|
|
|
'method' => $request->getMethod(), |
|
51
|
|
|
// Errbit uses this property to generate stack tracke |
|
52
|
|
|
'exception' => $exception |
|
53
|
|
|
] |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|