src/EventListener/ExceptionListener.php line 16

Open in your IDE?
  1. <?php
  2. /**
  3.  * User: broasca
  4.  * Date: 06.05.2021
  5.  * Time: 15:48
  6.  */
  7. namespace App\EventListener;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  10. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  11. class ExceptionListener
  12. {
  13.     public function onKernelException(ExceptionEvent $event)
  14.     {
  15. //        // todo change in production
  16. //
  17. //        // You get the exception object from the received event
  18. //        $exception = $event->getThrowable();
  19. //        $data = [
  20. //            'success' => false,
  21. //            'code' => $exception->getCode(),
  22. //            'message' => $exception->getMessage(),
  23. //        ];
  24. //
  25. //        // Customize your response object to display the exception details
  26. //        $response = new Response();
  27. //        $response->setContent(json_encode($data));
  28. //
  29. //        // HttpExceptionInterface is a special type of exception that
  30. //        // holds status code and header details
  31. //        if ($exception instanceof HttpExceptionInterface) {
  32. //            $response->setStatusCode($exception->getStatusCode());
  33. //            $response->headers->replace($exception->getHeaders());
  34. //        } else {
  35. //            $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
  36. //        }
  37. //
  38. //        // sends the modified response object to the event
  39. //        $event->setResponse($response);
  40.     }
  41. }