src/EventListener/APIExceptionListener.php line 23

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Logics Tecnologia e Serviços LTDA.
  4.  * @author: Romeu Godoi <romeu@logics.com.br>
  5.  * Date: 13/11/15
  6.  * Time: 16:47
  7.  * @copyright Copyright (C) 2015 LogicSITE. Todos os Direitos Reservados.
  8.  * LogicSITE. Este software é de propriedade exclusiva da LOGICS TEC. E SERV. LTDA
  9.  * e seu uso só pode ser dado por usuários licenciados por escrito.
  10.  * O uso indevido desta plataforma, ou parte dela estará sujeita a penalidades
  11.  * previstas em lei, conforme legislação pertinente.
  12.  */
  13. namespace App\EventListener;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  17. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  18. class APIExceptionListener
  19. {
  20.     public function onKernelException(ExceptionEvent $event)
  21.     {
  22.         // do whatever tests you need - in this example I filter by path prefix
  23. //        $path = $event->getRequest()->getRequestUri();
  24. //        if (preg_match('/^\/api\/v[0-9]\/*/', $path) == false /*||
  25. //        if (!in_array(
  26. //            $event->getRequest()->headers->get('content-type'),
  27. //            ['application/json', 'application/ld+json']
  28. //        )) {
  29. //            return;
  30. //        }
  31. //
  32. //        $exception = $event->getThrowable();
  33. //
  34. //        // Customize your response object to display the exception details
  35. //        $response = new JsonResponse();
  36. //        $response->setData([
  37. //            'success' => false,
  38. //            'message' => $exception->getMessage()
  39. //        ]);
  40. //
  41. //        // HttpExceptionInterface is a special type of exception that
  42. //        // holds status code and header details
  43. //        if ($exception instanceof HttpExceptionInterface) {
  44. //            $response->setStatusCode($exception->getStatusCode());
  45. ////            $response->headers->replace($exception->getHeaders());
  46. //        } else {
  47. //            $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
  48. //        }
  49. //
  50. //        // Send the modified response object to the event
  51. //        $event->setResponse($response);
  52.     }