Completed
Pull Request — master (#144)
by
unknown
12:31
created

ExceptionListener   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 1 Features 1
Metric Value
dl 0
loc 18
rs 10
c 2
b 1
f 1
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A onKernelException() 0 12 2
1
<?php
2
3
namespace AppBundle\EventListener;
4
5
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\Security\Core\Exception\AuthenticationException;
8
9
class ExceptionListener
10
{
11
    /**
12
     * @param GetResponseForExceptionEvent $event
13
     */
14
    public function onKernelException(GetResponseForExceptionEvent $event)
15
    {
16
        $exception = $event->getException();
17
18
        if ($exception instanceof AuthenticationException) {
19
            $response = new JsonResponse([
20
                'code' => $exception->getPrevious()->getCode(),
21
                'message' => $exception->getMessage(),
22
            ], 403);
23
            $event->setResponse($response);
24
        }
25
    }
26
}
27