55namespace PhpList \RestBundle \Common \EventListener ;
66
77use Exception ;
8+ use PhpList \Core \Domain \Identity \Exception \AdminAttributeCreationException ;
89use PhpList \Core \Domain \Subscription \Exception \SubscriptionCreationException ;
910use Symfony \Component \HttpFoundation \JsonResponse ;
1011use Symfony \Component \HttpKernel \Event \ExceptionEvent ;
1112use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
1213use Symfony \Component \HttpKernel \Exception \HttpExceptionInterface ;
14+ use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
15+ use Symfony \Component \Validator \Exception \ValidatorException ;
1316
1417class ExceptionListener
1518{
@@ -34,6 +37,21 @@ public function onKernelException(ExceptionEvent $event): void
3437 'message ' => $ exception ->getMessage (),
3538 ], $ exception ->getStatusCode ());
3639 $ event ->setResponse ($ response );
40+ } elseif ($ exception instanceof AdminAttributeCreationException) {
41+ $ response = new JsonResponse ([
42+ 'message ' => $ exception ->getMessage (),
43+ ], $ exception ->getStatusCode ());
44+ $ event ->setResponse ($ response );
45+ } elseif ($ exception instanceof ValidatorException) {
46+ $ response = new JsonResponse ([
47+ 'message ' => $ exception ->getMessage (),
48+ ], 400 );
49+ $ event ->setResponse ($ response );
50+ } elseif ($ exception instanceof AccessDeniedException) {
51+ $ response = new JsonResponse ([
52+ 'message ' => $ exception ->getMessage (),
53+ ], 403 );
54+ $ event ->setResponse ($ response );
3755 } elseif ($ exception instanceof Exception) {
3856 $ response = new JsonResponse ([
3957 'message ' => $ exception ->getMessage (),
0 commit comments