Skip to content

Commit d524ab5

Browse files
committed
ISSUE-345: AccessDeniedException
1 parent e2fdf7b commit d524ab5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Common/EventListener/ExceptionListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1212
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
1313
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
14+
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1415
use Symfony\Component\Validator\Exception\ValidatorException;
1516

1617
class ExceptionListener
@@ -46,6 +47,11 @@ public function onKernelException(ExceptionEvent $event): void
4647
'message' => $exception->getMessage(),
4748
], 400);
4849
$event->setResponse($response);
50+
} elseif ($exception instanceof AccessDeniedException) {
51+
$response = new JsonResponse([
52+
'message' => $exception->getMessage(),
53+
], 403);
54+
$event->setResponse($response);
4955
} elseif ($exception instanceof Exception) {
5056
$response = new JsonResponse([
5157
'message' => $exception->getMessage(),

0 commit comments

Comments
 (0)