Test Setup Failed
Branch master (1b2352)
by Valery
09:42
created

ExceptionListener   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A onKernelException() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\EventListener;
6
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
9
use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException;
10
11
final class ExceptionListener
12
{
13
    public function onKernelException(ExceptionEvent $event): void
14
    {
15
        $exception = $event->getThrowable();
16
        if ($exception instanceof TokenNotFoundException) {
17
            $customResponse = new JsonResponse([
18
                'status' => 'fail', 'message' => $exception->getMessage(),
19
            ], 419);
20
            $event->setResponse($customResponse);
21
        }
22
    }
23
}
24